PDA

View Full Version : Options (registerCallback) question



Varsuuk
March 17th, 2019, 20:46
*** SOLVED ***


I was tracing the Options behavior so I added code to char_main to call my handler then register that handler for future changes.

When I open the sheet it prints the current option value.

When I open options and cycle to next option (there are 2 only) it runs my callback with the "old" then the "new" value.
Is it supposed to call with existing value on "onSet" and then once set on "onChanged" (paraphrasing)

Not sure using it correctly.

Console output:


Runtime Notice: Host session started
Runtime Notice: s'mgr.abil: onInit'
Runtime Notice: s'>onHRSavingThrowMethodChanged'
Runtime Notice: s'categories'
Runtime Notice: s'<onHRSavingThrowMethodChanged'
Runtime Notice: s'template_common_sw.xml' | s'linkfield->onInit()' | s'isEmpty()' | bTRUE
Runtime Notice: s'template_common_sw.xml' | s'linkfield->onValueChanged()' | s'isEmpty()' | bTRUE
>>> I click on button to change from displayed Categories to SingleValue
Runtime Notice: s'>onHRSavingThrowMethodChanged'
Runtime Notice: s'categories'
Runtime Notice: s'<onHRSavingThrowMethodChanged'
Runtime Notice: s'>onHRSavingThrowMethodChanged'
Runtime Notice: s'default'
Runtime Notice: s'<onHRSavingThrowMethodChanged'
>>> I click on button to change from displayed SingleValue to Categories
Runtime Notice: s'>onHRSavingThrowMethodChanged'
Runtime Notice: s'default'
Runtime Notice: s'<onHRSavingThrowMethodChanged'
Runtime Notice: s'>onHRSavingThrowMethodChanged'
Runtime Notice: s'categories'
Runtime Notice: s'<onHRSavingThrowMethodChanged'
...






function onInit()
if User.isHost() then
-- Add right-click menu options for DM to give an individual character a long or short rest.
registerMenuItem(Interface.getString("menu_rest"), "lockvisibilityon", MENU_REST_POS);
registerMenuItem(Interface.getString("message_restovernight"), "pointer_cone", MENU_REST_POS, MENU_REST_OVERNIGHT_POS);
registerMenuItem(Interface.getString("message_restfull"), "pointer_circle", MENU_REST_POS, MENU_REST_FULL_POS);
end

if User.isLocal() then
portrait.setVisible(false);
localportrait.setVisible(true);
end


OptionsManager.registerCallback("HouseRule_SavingThrowMethod", onHRSavingThrowMethodChanged);


onHRSavingThrowMethodChanged(); -- TODO put with other loading methods once work on that
end

function onClose()
OptionsManager.unregisterCallback("HouseRule_SavingThrowMethod", onHRSavingThrowMethodChanged);
end


function onHRSavingThrowMethodChanged()
Debug.console(">onHRSavingThrowMethodChanged");
local sOptHRSaves = OptionsManager.getOption("HouseRule_SavingThrowMethod");
Debug.console(sOptHRSaves);
Debug.console("<onHRSavingThrowMethodChanged");
-- TODO ---> Add real work for the handler
end

Moon Wizard
March 25th, 2019, 21:57
Just looking at this.

It looks like the OptionsManager code is calling the callbacks twice (for non-local options, i.e. GM-only options). And that the first one is returning the old value incorrectly on getOption calls. The second callback should return the correct value during getOption. It's because the GM-only options are stored in the database vs. the local options being stored in the campaign registry. I'll look at updating the OptionsManager code in the next Test build to correct it to only call the callback once after the value has been changed.

Regards,
JPG

Varsuuk
March 25th, 2019, 22:47
Cool, it looked like a Prior and New set but there was no distinguisher. I had a workaround but wasn’t sure was good in anything but the tested case ;)

I’m not using it yet, was just learning how to add my first “homebrew” options setting for my ongoing rule set work.

Gracias :)

Varsuuk
August 10th, 2019, 01:15
I got home from work and searched on my old post and found it.
Since there was no follow up post and Moon usually indicates when something done (he might have in the releases or beta threads though - I don't follow them yet), figured worth updating since I was seeing weird stuff (which might be all in my head) when working on options last night but not sure until I redo this example test if it is the same thing or me misclicking :)

Varsuuk
August 12th, 2019, 06:00
Yup, verified this is still an issue:

Runtime Notice: Reloading ruleset
Runtime Notice: s'char_main->onClose()'
Ruleset Warning: Font (windowtitle): Windows replaced specified font face (Alegreya Sans SC Bold) with (Alegreya Sans SC)
Ruleset Warning: font: FGF initialization failed. Name (sidebar). File (graphics/graphics_fonts_adnd.xml)
Ruleset Warning: font: FGF initialization failed. Name (sheetlabelmini_percent). File (graphics/graphics_fonts_adnd.xml)
Ruleset Warning: font: FGF initialization failed. Name (arial-regular-6). File (graphics/graphics_fonts_adnd.xml)
Ruleset Warning: font: FGF initialization failed. Name (arial-regular-7). File (graphics/graphics_fonts_adnd.xml)
Ruleset Warning: font: FGF initialization failed. Name (arial-bold-7). File (graphics/graphics_fonts_adnd.xml)
Ruleset Warning: font: FGF initialization failed. Name (arial-regular-8). File (graphics/graphics_fonts_adnd.xml)
Ruleset Warning: font: FGF initialization failed. Name (arial-regular-9). File (graphics/graphics_fonts_adnd.xml)
Ruleset Warning: font: FGF initialization failed. Name (arial-regular-10). File (graphics/graphics_fonts_adnd.xml)
Ruleset Warning: font: FGF initialization failed. Name (arial-bold-12). File (graphics/graphics_fonts_adnd.xml)
Runtime Notice: s'>onHRSavingThrowMethodChanged()'
Runtime Notice: databasenode = { charsheet.id-00002 }
Runtime Notice: s'categories'
Runtime Notice: s'<onHRSavingThrowMethodChanged()'
Runtime Notice: s'template_common_sw.xml' | s'linkfield->onInit()' | s'isEmpty()' | bTRUE
Runtime Notice: s'template_common_sw.xml' | s'linkfield->onValueChanged()' | s'isEmpty()' | bTRUE
Runtime Notice: s'char_main->onInit()'
<<<< Here I click to switch from Categories to Default >>>>
Runtime Notice: s'>onHRSavingThrowMethodChanged()'
Runtime Notice: databasenode = { charsheet.id-00002 }
Runtime Notice: s'categories'
Runtime Notice: s'<onHRSavingThrowMethodChanged()'
Runtime Notice: s'>onHRSavingThrowMethodChanged()'
Runtime Notice: databasenode = { charsheet.id-00002 }
Runtime Notice: s'default'
Runtime Notice: s'<onHRSavingThrowMethodChanged()'

Moon Wizard
August 12th, 2019, 22:00
I just added a check into the CoreRPG desktop decal callback, and it correctly only called the registered callback once.

s'DDCL update' | s'desktopdecal_sw'
s'DDCL update' | s'off'
s'DDCL update' | s'desktopdecal_sw'
s'DDCL update' | s'off'
s'DDCL update' | s'desktopdecal_sw'
s'DDCL update' | s'off'

Not sure why you would still being seeing this.
* Are you using the latest CoreRPG version (i.e. no unzipped versions in your ruleset directory)?
* Are you defining your own OptionsManager global script?
* Are you calling that function from another script location?
* Are you registered the callback function twice?

Regards,
JPG

Varsuuk
August 12th, 2019, 23:27
Thanks for the update. I will check, it is VERY likely that I am pointing to the wrong spot. In my dev environ (laptop) I keep each zip file unpacked and gitted every time I update (which I did last Sat) so I can review changes if need and easily search in other rulesets.

Now that know it works, will see what I did wrong. Assumed since there wasn’t a reply long back that it fell under radar.

Sorry to give false alert. Will look at it once home from office.

Varsuuk
August 13th, 2019, 00:06
Oh boy... THANK you and glad I posted this.

Somehow, along with my S&W ruleset link to my eclipse project dir (so don't have to keep copying the ruleset) I somehow had links to 5E, AD&D 2E (old one) and CORERPG!
I deleted these three and started a re-update (since GCT has WiFi ;) ) and will retest and I am sure it will go away. Plus I will get lots of new stuff since MARCH 19th - the time of the link's creation

Varsuuk
August 13th, 2019, 00:47
Yup, it’s fixed all right.

Sorry about that and thank you :)