PDA

View Full Version : Another question by me this time about datasources



meathome
May 7th, 2010, 13:55
Hi again, I am beginning to fell bad about posting so many questions...

I have discovered a strange problem.

When the charactersheet is open in the gm-s window and the players window and either one of them clicks on the checkboxes too fast then the values become desynchronised

I have 1 numberfield with the following code and 4 checkboxes.
The checkboxes are added as datasources and the intetion is to add or remove 5 points to the numberfield.

When I test it on my own machine everything works fine, but when testing it with a remote player I get the desynchronisation errors... After a few tries the values in the numberfield dont match anymore and I have no idea why or how I can solve this.

Here is the code:


local trainingCount;

function onInit()
addSource("trained1");
addSource("trained2");
addSource("trained3");
addSource("trained4");
trainingCount=0;

trainingCount=sources["trained1"].getValue()
+sources["trained2"].getValue()
+sources["trained3"].getValue()
+sources["trained4"].getValue();

if trainingCount~=0 then
setReadOnly(true);
else
setReadOnly(false);
end
end

function onSourceUpdate()

local newCount=0;

newCount=sources["trained1"].getValue()
+sources["trained2"].getValue()
+sources["trained3"].getValue()
+sources["trained4"].getValue();

newCount=newCount-trainingCount;
if newCount~=0 then
setValue(getValue()+newCount*5);
trainingCount=trainingCount+newCount;
end

if trainingCount~=0 then
setReadOnly(true);
else
setReadOnly(false);
end

end

function onValueChanged()

playerId=window.getDatabaseNode().getParent().getP arent().getName();
sNode="charsheet." .. playerId .. ".skills"

tSkills=DB.findNode(sNode).getChildren();

for k, w in pairs(tSkills) do

if w.getChild("stat").getValue()==window.label.getValue() then
w.getChild("stat").setValue(window.label.getValue());
end
end

return true;

end


Thanks for any help

Moon Wizard
May 7th, 2010, 17:43
You might try looking at the rewrite of the checkbox that I did in the 4E ruleset. I ran into some issues with the original checkbox, so I rewrote portions of the checkbox scripting code.

In the future, I am planning on replacing the checkbox class with the iconcycler class in the 4E ruleset, since it really a multi-select checkbox.

Cheers,
JPG

meathome
May 8th, 2010, 12:04
Hi,

It was my fault not the checkboxe's. The problem was that I didnt use a databasenode to store the number of activated checkboxes.

I stored that data localy, and that caused desynch issues because of netlag

Thanks for the help!