PDA

View Full Version : DB addHandler onUpdate not being called on Client



MadBeardMan
January 5th, 2019, 22:33
Greetings All,

I've got some code that works with Target/Difficulty Numbers. It's part of the WOIN ruleset and works a treat.

However I've copied it over to the Vampire ruleset I'm working on and it's not working, yet the code is indentical in both rulesets.

This is the lua script:


local nodeSource = nil;
local bLocked = false;

function onInit()
DB.addHandler("desktoppanel.targetnumber", "onAdd", onSourceUpdate);
DB.addHandler("desktoppanel.targetnumber", "onUpdate", onSourceUpdate);

setValue(DB.getValue("desktoppanel.targetnumber", 0));

end

function onClose()
DB.removeHandler("desktoppanel.targetnumber", "onAdd", onSourceUpdate);
DB.removeHandler("desktoppanel.targetnumber", "onUpdate", onSourceUpdate);
end

function onSourceUpdate()
print('SourceUpdate1')
if bLocked then return; end
bLocked = true;
setValue(DB.getValue("desktoppanel.targetnumber", 0));
print('SourceUpdate')
bLocked = false;
end

function onValueChanged()
if bLocked then return; end
bLocked = true;
print('ValueChanged1')
if User.isHost() then
DB.setValue("desktoppanel.targetnumber", "number", getValue());
print('ValueChanged')
end
bLocked = false;
end

On the Client it's calling the script, running a 'ValueChanged1' as it resets it to 0 in the init, but because it's not 'User.isHost()' it doesn't update it.

However, if I change the value on the host, it doesn't call the onSourceUpdate.

It's very odd, any thoughts are welcome! Can't see how identical code can run differently, and if I run a WOIN adventure it all works.

Cheers,
MBM

MadBeardMan
January 5th, 2019, 23:04
Seems the Node being created in the db.xml by the Host isn't being made public.

How odd.

MadBeardMan
January 5th, 2019, 23:12
Ok had to add this code to the onInit()


function onInit()
DB.addHandler("desktoppanel.targetnumber", "onAdd", onSourceUpdate);
DB.addHandler("desktoppanel.targetnumber", "onUpdate", onSourceUpdate);

setValue(DB.getValue("desktoppanel.targetnumber", 0));

if User.isHost() then
if DB.isPublic("desktoppanel") == false then
DB.setPublic("desktoppanel", true)
end
end

end

Must be a difference between the two rulesets as to why it's not public in Vampire but is public in WOIN.

Any clues would be great, though this is solved for the moment.

Cheers
MBM

Moon Wizard
January 7th, 2019, 02:14
Nodes are not public unless they explicitly set to public via script or via user action (i.e. drop on chat).

You'll find most of the default CoreRPG public node setup in Desktop.registerPublicNodes()

Regards,
JPG