FG Spreadshirt Swag
Page 5 of 5 First ... 345
  1. #41
    I think if it keeps being too much of a pain, that adding a couple addHandlers might be the way I might have to go in the init... But... I don't know how to use those to keep an eye on or extract the effect, since I haven't looked into handlers yet... Any advice on this?

  2. #42
    Make sure to use Debug.chat and Debug.console extensively while developing to inspect variables in situations where things aren’t working as expected.

    If you are making multiple passes through the combat tracker nodes, you will need to request the attributes/token during each pass, especially since you are changing things during each pass.

    Again, use Debug.chat/console during the loops to inspect the variables to make sure they are what you expect.

    Regards,
    JPG

  3. #43
    Still sitting at the same wall, with no progress...

    As much as I dislike posting walls of code (i prefer the more short and to the point)... I am having a rough time hunting down this one... I have placed MANY Debug.console checks inside the entire code... I will post the loop and explain what I am seeing/doing, to hopefully aid in hunting down the reason for the error... Console log will be at bottom of post...

    First, The Init code, to setup the basis of the loop, using updateEffectsHelper to keep an eye on the effects and help trigger the event:
    Code:
    function onInit()
    	orgUpdateEffectsHelper = TokenManager.updateEffectsHelper;
    	TokenManager.updateEffectsHelper = shiftedUpdateEffectsHelper;
    end
    Then the function trigger from the loop:
    Code:
    function shiftedUpdateEffectsHelper(tokenCT, nodeCT)
    			Debug.console("ATTENTION: shiftedUpdateEffectsHelper initiated");
    	orgUpdateEffectsHelper(tokenCT, nodeCT);
    			Debug.console("ATTENTION: orgUpdateEffectsHelper initiated");
    	if not procShiftedActive then
    		procShiftedActive = true;
    		processShifted(nodeCT,true,true);
    		procShiftedActive = false;
    	end
    
    end
    Next, the function that pulls the effect and triggers the processes of changing the token and such when the effect is added to the character:
    Code:
    function processShifted(nodeUnit,processStats,processToken)
    	local sTargetType, nodeTarget = ActorManager.getTypeAndNode(nodeUnit);
    	if sTargetType == "pc" or sTargetType == "ct" then
    		for _,nodeChild in pairs(DB.getChildren(nodeUnit, "effects")) do
    			local rEffect = EffectManager.getEffect(nodeChild);
    			if rEffect and (rEffect.sName or "") ~= "" then
    				if string.sub(rEffect.sName,1,8) == "Shifted;" then
    					if processStats then
    						setShiftedStats(sTargetType, nodeTarget, rEffect);
    						Debug.console("ATTENTION: setShiftedStats initiated");
    						setShiftedHP(sTargetType, nodeTarget, rEffect);
    						Debug.console("ATTENTION: setShiftedHP initiated");
    					end
    					if processToken then
    						setShiftedToken(sTargetType, nodeTarget, nodeUnit, rEffect);
    						Debug.console("ATTENTION: setShiftedToken initiated");
    					end
    				end
    			end
    		end
    		if processStats then
    			clearShiftedStats(sTargetType, nodeTarget);
    			Debug.console("ATTENTION: clearShiftedStats initiated");
    		end
    		if processToken then
    			clearShiftedToken(sTargetType, nodeTarget, nodeUnit);
    			Debug.console("ATTENTION: clearShiftedToken initiated");
    		end
    	end
    end
    Now the console readout:
    Before Event Trigger:
    Code:
    Runtime Notice: s'ATTENTION: tokenCT = ' | tokeninstance = { { container = image.id-00001.image, id = 262, scale = 3.216, x,y = 1551,651 } }
    Runtime Notice: s'ATTENTION: shiftedUpdateEffectsHelper initiated'
    Runtime Notice: s'ATTENTION: orgUpdateEffectsHelper initiated'
    Runtime Notice: s'token Scale Set'
    Runtime Notice: s'ATTENTION: setShiftedToken COMPLETED'
    Runtime Notice: s'ATTENTION: setShiftedToken initiated'
    Runtime Notice: s'ATTENTION: clearShiftedStats STARTED'
    Runtime Notice: s'revert stats process'
    Runtime Notice: s'ATTENTION: clearShiftedStats COMPLETED'
    Runtime Notice: s'ATTENTION: clearShiftedStats initiated'
    Runtime Notice: s'ATTENTION: clearShiftedToken STARTED'
    Runtime Notice: s'begining clear shifted process'
    Runtime Notice: s'clear shifted process User Host check'
    Runtime Notice: s'token Scale revert'
    Runtime Notice: s'ATTENTION: clearShiftedToken COMPLETED'
    Runtime Notice: s'ATTENTION: clearShiftedToken initiated'
    Event Triggered, processing:
    Code:
    Runtime Notice: s'ATTENTION: tokenCT = ' | tokeninstance = { { container = image.id-00001.image, id = 262, scale = 3.216, x,y = 1551,651 } }
    Runtime Notice: s'ATTENTION: shiftedUpdateEffectsHelper initiated'
    Runtime Notice: s'ATTENTION: orgUpdateEffectsHelper initiated'
    Runtime Notice: s'ATTENTION: setShiftedStats STARTED'
    Runtime Notice: s'Setting new Stats'
    Runtime Notice: s'ATTENTION: setShiftedStats COMPLETED'
    Runtime Notice: s'ATTENTION: setShiftedStats initiated'
    Runtime Notice: s'ATTENTION: setShiftedHP STARTED'
    Runtime Notice: s'Begin setShiftedHP'
    Runtime Notice: s'user host check for shifted hp'
    Runtime Notice: s'PreShiftedHP = ' | #29
    Runtime Notice: s'PreShiftedWounds = ' | #4
    Runtime Notice: s'ACTIVEHP = ' | #34
    Runtime Notice: s'ACTIVEWOUNDS = ' | #0
    Runtime Notice: s'ATTENTION: setShiftedHP initiated'
    Runtime Notice: s'ATTENTION: setShiftedToken STARTED'
    Runtime Notice: s'early tokenCT = ' | tokeninstance = { { container = image.id-00001.image, id = 262, scale = 3.216, x,y = 1551,651 } }
    Runtime Notice: s'oldTokenInstance = ' | tokeninstance = { { container = image.id-00001.image, id = 262, scale = 3.216, x,y = 1551,651 } }
    Runtime Notice: s'nodeContainerOld = ' | databasenode = { image.id-00001.image }
    Runtime Notice: s'x,y = ' | #1551 | #651
    Runtime Notice: s'nodeContainerOld.getNodeName' | s'image.id-00001.image'
    Runtime Notice: s'ImgCntrl = ' | { #1 = tokeninstance = { { container = image.id-00001.image, id = 262, scale = 3.216, x,y = 1551,651 } }, #2 = tokeninstance = { { container = image.id-00001.image, id = 263, scale = 2.5125, x,y = 1551,651 } } }
    Runtime Notice: s'ATTENTION: tokenCT = ' | tokeninstance = { { container = image.id-00001.image, id = 263, scale = 2.5125, x,y = 1551,651 } }
    Continue Loop, scale adjusted during this loop:
    Code:
    Runtime Notice: s'ATTENTION: shiftedUpdateEffectsHelper initiated'
    Runtime Notice: s'ATTENTION: orgUpdateEffectsHelper initiated'
    Runtime Notice: s'link complete'
    Runtime Notice: s'update vis complete'
    Runtime Notice: s'update targets complete'
    Runtime Notice: s'updateName complete'
    Runtime Notice: s'ATTENTION: tokenCT = ' | tokeninstance = { { container = image.id-00001.image, id = 263, scale = 2.5125, x,y = 1551,651 } }
    Runtime Notice: s'ATTENTION: shiftedUpdateEffectsHelper initiated'
    Runtime Notice: s'ATTENTION: orgUpdateEffectsHelper initiated'
    Runtime Notice: s'updateEffects complete'
    Runtime Notice: s'replaceCombatantToken complete'
    Runtime Notice: s'ImgCntrl = ' | { #1 = tokeninstance = { { container = image.id-00001.image, id = 263, scale = 2.5125, x,y = 1551,651 } } }
    Runtime Notice: s'tokenCT = ' | tokeninstance = { { container = image.id-00001.image, id = 263, scale = 2.5125, x,y = 1551,651 } }
    Token changed and rescaled, continuing the loop: and now what happens up till error:
    Code:
    Runtime Notice: s'ATTENTION: tokenCT = ' | tokeninstance = { { container = image.id-00001.image, id = 263, scale = 6.432, x,y = 1551,651 } }
    Runtime Notice: s'ATTENTION: shiftedUpdateEffectsHelper initiated'
    Runtime Notice: s'ATTENTION: orgUpdateEffectsHelper initiated'
    Runtime Notice: s'token Scale Set'
    Runtime Notice: s'ATTENTION: setShiftedToken COMPLETED'
    Runtime Notice: s'ATTENTION: setShiftedToken initiated'
    Runtime Notice: s'ATTENTION: clearShiftedStats STARTED'
    Runtime Notice: s'revert stats process'
    Runtime Notice: s'ATTENTION: clearShiftedStats COMPLETED'
    Runtime Notice: s'ATTENTION: clearShiftedStats initiated'
    Runtime Notice: s'ATTENTION: clearShiftedToken STARTED'
    Runtime Notice: s'begining clear shifted process'
    Runtime Notice: s'clear shifted process User Host check'
    Runtime Notice: s'token Scale revert'
    Runtime Notice: s'ATTENTION: clearShiftedToken COMPLETED'
    Runtime Notice: s'ATTENTION: clearShiftedToken initiated'
    Script Error: [string "scripts/manager_token.lua"]:378: attempt to index local 'tokenCT' (a userdata value)
    So after the token is changed...the loop runs 1 more complete time, and then has an error with tokenCT upon either completion, or while trying to continue the loop.

    I originally used updateEffectsHelper while using bitmapWidget to display an image... I had no issue... but now I am swapping tokens...

    Any advice or insight?
    Last edited by Diablobob; January 8th, 2019 at 17:43.

  4. #44
    It's because you're changing the token in the middle of a bunch of code in the TokenManager, and replacing a single function. In this case, the tokenCT variable is passed into multiple functions, both "updateEffectsHelper" as well as "updateTooltip". Because you are replacing updateEffectsHelper and changing the token, then the token variable is invalid when it is subsequently passed to updateTooltip.

    I think you should rethink your approach to this. Trying to insert a single override function and change information that's being referenced in the original global script will always be problematic, and will most likely break on updates.

    If you are trying to trigger on "effects" being added/updated; then you need to use database handlers to capture the add/update/delete events. There are already a couple hooks in CombatManager that might be good enough for what you want. See setCustomAddCombatantEffectHandler/setCustomDeleteCombatantEffectHandler; which passes the nodeCT and the nodeEffect as two variables to your callback function you provide to the initial setCustom call. If you want to totally manage yourself, look at the addHandler calls at the top of CombatManager global script for an example of settings up your own monitoring.

    Regards,
    JPG

  5. #45
    I know it has been a bit... I have been ill lately, hence the lack of messages... Thank you by the way!...

    I can get the script to trigger on an effect added, but having issues having it parse the effect string... it is passing over that part of my script completely...

    Code:
    function onInit()
    	CombatManager.setCustomAddCombatantEffectHandler(shiftedUpdateEffectsHelper);
    	CombatManager.setCustomDeleteCombatantEffectHandler(shiftedUpdateEffectsHelper);
    end
    Code:
    function shiftedUpdateEffectsHelper(nodeCT)
    			Debug.console("ATTENTION: onShiftEffectAdded initiated");
    	if not procShiftedActive then
    		procShiftedActive = true;
    		processShifted(nodeCT,true,true);
    		procShiftedActive = false;
    	end
    end
    Code:
    function processShifted(nodeUnit,processStats,processToken)
    	local sTargetType, nodeTarget = ActorManager.getTypeAndNode(nodeUnit);
    	if sTargetType == "pc" or sTargetType == "ct" then
    		for _,nodeChild in pairs(DB.getChildren(nodeUnit, "effects")) do
    			local rEffect = EffectManager.getEffect(nodeChild);
    			if rEffect and (rEffect.sName or "") ~= "" then
    				if string.sub(rEffect.sName,1,8) == "Shifted;" then
    					if processStats then
    						setShiftedStats(sTargetType, nodeTarget, rEffect);
    						Debug.console("ATTENTION: setShiftedStats initiated");
    						setShiftedHP(sTargetType, nodeTarget, rEffect);
    						Debug.console("ATTENTION: setShiftedHP initiated");
    					end
    					if processToken then
    						setShiftedToken(sTargetType, nodeTarget, nodeUnit, rEffect);
    						Debug.console("ATTENTION: setShiftedToken initiated");
    					end
    				end
    			end
    		end
    		if processStats then
    			clearShiftedStats(sTargetType, nodeTarget);
    			Debug.console("ATTENTION: clearShiftedStats initiated");
    		end
    		if processToken then
    			clearShiftedToken(sTargetType, nodeTarget, nodeUnit);
    			Debug.console("ATTENTION: clearShiftedToken initiated");
    		end
    --	end
    end
    The console readout is showing:
    Code:
    Runtime Notice: Reloading ruleset
    Runtime Notice: s'ATTENTION: onShiftEffectAdded initiated'
    Runtime Notice: s'ATTENTION: clearShiftedStats STARTED'
    Runtime Notice: s'revert stats process'
    Runtime Notice: s'ATTENTION: clearShiftedStats COMPLETED'
    Runtime Notice: s'ATTENTION: clearShiftedStats initiated'
    Runtime Notice: s'ATTENTION: clearShiftedToken STARTED'
    Runtime Notice: s'begining clear shifted process'
    Runtime Notice: s'clear shifted process User Host check'
    Runtime Notice: s'token Scale revert'
    Runtime Notice: s'ATTENTION: clearShiftedToken COMPLETED'
    Runtime Notice: s'ATTENTION: clearShiftedToken initiated'
    I'm confused why it's not reading the effect string. I'm pretty sure I'm just having another irritating syntax issue.

    Any suggestions?

  6. #46
    Still haven't been able to make progress... If I use an add handler, the function is triggered like it should... But the string isn't read...

    Should I be using getString() function or something... It works with the override... Why not with the handler?

    Please help! This is extremely frustrating!

  7. #47
    I looked closer at the CombatManager effect add/delete code; and I'm thinking that it may not work for your situation. It looks like it's not used with any of the other rulesets layered on CoreRPG; probably because the "add" event triggers before the label is set. It's the way that the client works (i.e. record is added, before any child values can be set).

    Most likely, you are better off setting up your own effect handler processing code. Maybe something like this:
    Code:
    function onInit()
    	Interface.onDesktopInit = onDesktopInit;
    end
    
    function onDesktopInit()
    	DB.addHandler(DB.getPath(CombatManager.CT_COMBATANT_PATH, "*.effects.*.label"), "onUpdate", onEffectLabelChanged);
    	DB.addHandler(DB.getPath(CombatManager.CT_COMBATANT_PATH, "*.effects"), "onChildDeleted", onEffectDeleted);
    end
    
    function onEffectDeleted(nodeEffectList)
      local nodeCT = DB.getChild(nodeEffectList, "..");
      processShifted(nodeCT);
    end
    
    function onEffectLabelChanged(nodeField)
      local nodeCT = DB.getChild(nodeField, "....");
      processShifted(nodeCT);
    end
    I did this code off the top of my head; so you might want to use Debug.chat or Debug.console to make sure I got the nodeCT variable set up correctly.

    Regards,
    JPG

  8. #48
    I got the token swap working... however the problem currently is that only the GM can initiate the token swap.. if the player tries, then there are errors "I'm assuming it's because token changes can only be done by the User.isHost"... The player isn't directly affecting the token, the script is triggering when the player applies an effect to themselves... but it looks like the script is assuming the player permissions, and not the GM...

    Since the host is running the extension, is there a way to allow the script to assume the ishost permissions to change the token? or for the GM

  9. #49

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
5E Product Walkthrough Playlist

Log in

Log in