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
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