PDA

View Full Version : Host side AND Player side running code issue



celestian
March 15th, 2018, 04:21
I've noticed a bug in my AdvancedEffects extension and it's got me baffled and probably due to something I'm not aware of in how FG handles things.

When a game is running and the player opens up a character sheet and "equips" a weapon with effects it applies them normally. Remove item, effects are removed.

Stop, close FG. Restart.

When a game is running and the DM opens up the same character sheet and "equips" a weapon with effects it applies them normally. Remove item, effects are removed.

Stop, close FG. Restart.

When a game is running and the DM opens up the character sheet and the player ALSO opens the character sheet and then the player equips an item with effects the effects are applied twice.

I added debug code to see what is up and what is happening is that the code is being executed on the Host AND player side if they both have the character sheet opened.

Anyone have an idea why it does this and how best to build in logic to counter act it?

Nickademus
March 15th, 2018, 04:52
Sounds like you have a message being sent to all clients (that have registered for it via opening the character sheet). I assume that it is not to equip button that is applying the effect, but rather something further up the chain that is listening for an event from the equip button. Thus both the Host client and Player client hear the event and apply the effect.

celestian
March 15th, 2018, 04:56
Sounds like you have a message being sent to all clients (that have registered for it via opening the character sheet). I assume that it is not to equip button that is applying the effect, but rather something further up the chain that is listening for an event from the equip button. Thus both the Host client and Player client hear the event and apply the effect.

Hum, there are certainly handlers. I'll try printstack() and see if that helps me track it down. Thanks for the suggestion!

Bidmaron
March 15th, 2018, 05:03
Does printstack() really work? Never even tried it. Thought it was part of the unimplemented LUA portions.

celestian
March 15th, 2018, 05:22
Does printstack() really work? Never even tried it. Thought it was part of the unimplemented LUA portions.

Yeap, works for me at least. Here is an example. notifyEffectAdd is nearest function and the further down you go are the paths that got to notifyEffectAdd.



Script Notice:
stack traceback:
[string "scripts/manager_effect_adnd.lua"]:39: in function 'notifyEffectAdd'
[string "scripts/manager_effect_adnd.lua"]:190: in function 'updateItemEffect'
[string "scripts/manager_effect_adnd.lua"]:127: in function 'updateItemEffects'
[string "campaign/scripts/char_invlist_adnd.lua"]:183: in function 'updateItemEffects'
[string "campaign/scripts/char_invlist_adnd.lua"]:121: in function <[string "campaign/scripts/char_invlist_adnd.lua"]:98>

celestian
March 15th, 2018, 05:29
Hum, there are certainly handlers. I'll try printstack() and see if that helps me track it down. Thanks for the suggestion!

Sure enough, it's the DB.addHandler(DB.getPath(node, "*.carried"), "onUpdate", onCarriedChanged); getting run for both sides (onCarriedChanged).

I'm not sure how tho because I check for existence of the effects via source (the item's path) before I add it. I'll go over that and see why it's not working here.

celestian
March 15th, 2018, 06:16
What I ended up having to do is check in the handlerApplyEffect() function and re-verify the effect source was not in any effects on that node. Unless there is some other way to ensure addHandler only is run once even if it's open on more than one user's copy of FG that'll have to work.

Moon Wizard
March 15th, 2018, 20:41
You’d have to move your effect application to a global script handler registration that only runs on the host, instead of running on the character sheet. Since only he host can apply effects and the combat tracker , this seems like it would be a good way to go anyway.

Regards,
JPG

celestian
March 16th, 2018, 00:13
You’d have to move your effect application to a global script handler registration that only runs on the host, instead of running on the character sheet. Since only he host can apply effects and the combat tracker , this seems like it would be a good way to go anyway.

Regards,
JPG

I was actually converting it to a OOB style when I noticed this. Originally I had all kinds of stuff dealing with permissions, checking who "owned" a pc/etc to give them ownership/etc. But since then I figured out OOB and came back to drop all that mess. The problem was that with both people having the sheet opened it triggered the OOB notify twice when the "carried" variable was updated. I did add in a check in the "apply" section which catches if it's sent twice but if there is a way to only have the trigger sent once when there are multiple folks opening the sheets I'd be happy to experiment with it to figure it out.

What is the "global script handler"?

Moon Wizard
March 16th, 2018, 01:01
You make a global script, like "ActionsManager" or "ActionAttack". Then, put the handler registration code into the onInit for the global script, but only is User.isHost() == true; Your handler would be looking at any database nodes matching "charsheet.*.inventorylist.*.carried". Then, you only have one trigger for when the carried state changes on a PC item. The host will get every notification, since the host is the database master.

Cheers,
JPG

Bidmaron
March 16th, 2018, 05:06
Celestian, you can please disregard my question in the other thread since you answered everything right here.

celestian
March 16th, 2018, 06:10
You make a global script, like "ActionsManager" or "ActionAttack". Then, put the handler registration code into the onInit for the global script, but only is User.isHost() == true; Your handler would be looking at any database nodes matching "charsheet.*.inventorylist.*.carried". Then, you only have one trigger for when the carried state changes on a PC item. The host will get every notification, since the host is the database master.

Cheers,
JPG

Oh geeze. Yeah I didn't think about just adding a handler for "charsheet.*.inventorylist...." specifically like that. Thanks! I'll give it a shot.

celestian
March 16th, 2018, 06:56
Oh geeze. Yeah I didn't think about just adding a handler for "charsheet.*.inventorylist...." specifically like that. Thanks! I'll give it a shot.

Got it working. Was actually a lot simpler than the other 2 methods I tried to do this with! Just adding the addHandler for the charsheets of all of them worked very well. The only issue I've noticed is when I tried to removeHandler in an onClose() it would error out. I'm guessing it's because the only time it closes is when FG shuts down or /reload is run... which I guess means it's released because everything is?

I've got a few more bits to clean up but so far, works great!