PDA

View Full Version : onUpdate recursive node event issue



celestian
February 27th, 2017, 02:09
So, I'm trying to add "skills". I have the following fields, base/class_adj/stat_adj/armor_adj/total AND a cycle select. Total has the onUpdate that will collect all those values and set itself to them.

The cycle select will let the player choose from nothing/percentile/str/dex/con/int/wis/char. When it cycles I am trying to set the base based on what they select (if they select str I set the base to the str score/etc). When I set the base value I get the alert of a recursive node event. The change to the base is causing the onUpdate bit for total to run again.

This is the bit that sets it.


nValue = DB.getValue(nodeChar, "abilities." .. sAbility .. ".score", 0);
DB.setValue(nodeSkill, "base_check","number", nValue);


I'm trying to think how to get around this. I want the user to be able to set the base but default it to the stat (if they select a stat with the cycler) and they can change it if they want.

Any suggestions?

edit...update

As a work around for now I've just made the base_check field hidden if they select the ability score types and just fill that in behind using ability score.

Moon Wizard
February 27th, 2017, 22:57
You get the recursive event warning when you create an endless cycle within your code. (Ex: you write an onValueChanged handler that calls setValue on itself)

In this case, something in your onUpdate handler code is triggering an action that changes the database value that triggered the original onUpdate event.

To remove the warning, you need to rework your logic or data structure so that the onUpdate code doesn't modify the original database node that triggers the event.

Regards,
JPG

celestian
February 27th, 2017, 23:04
You get the recursive event warning when you create an endless cycle within your code. (Ex: you write an onValueChanged handler that calls setValue on itself)

In this case, something in your onUpdate handler code is triggering an action that changes the database value that triggered the original onUpdate event.


Yup, sorry I thought I explained that bit. I was setting a field that caused an update within the onUpdate.



To remove the warning, you need to rework your logic or data structure so that the onUpdate code doesn't modify the original database node that triggers the event.

Regards,
JPG

That's the tricky part I couldn't figure out. Well, I did but I'm not sure it's best. I just removed base_check update and "hide" the box when it's not percentile (it's str/dex/etc) and then just retrieve current dex/str/whatever during the check/total calc from mods.

I couldn't think around it to come up with an option that let me set the value to a default with ability score option selected.

Moon Wizard
February 28th, 2017, 02:22
It's impossible to tell without seeing all the XML/Lua for the class, as well as the controls. It's possible you already have a reasonable solution, so just go with it if it works.

Cheers,
JPG

celestian
March 8th, 2017, 06:01
Figured I'd post a working "solution" incase anyone else runs into this problem.

So, while futzing with something else I ran into a problem I needed to set something with an onUpdate set. This was just for testing so I wanted to make it work... and I thought of trying this which seems to work.



DB.removeHandler(nodeWeapon.getNodeName(), "onChildUpdate", onDataChanged);
DB.setValue(v, "damageasstring","string",sDamage);
DB.addHandler(nodeWeapon.getNodeName(), "onChildUpdate", onDataChanged);


Basically I turn off checking for update then turn it back on after the value is set. Probably not the best way to do it (this is just temporary) but it works.