PDA

View Full Version : setValue not actually setting Data issue.



drahkar
September 2nd, 2010, 09:44
Ok. I finally admit it. I'm a little stumped. Can someone look over the following code and let me know why the setValue() call in it isn't actually setting any data to the node?



function setdiepool( prcQscore, statName)
print("prcQscore: " .. prcQscore);
print("statName: " ..statName);
local highDieCountsource = window.getDatabaseNode().createChild("qualities." .. statName .. ".diepool.high.count");
local highDieTypesource = window.getDatabaseNode().createChild("qualities." .. statName .. ".diepool.high.type");
local lowDieCountsource = window.getDatabaseNode().createChild("qualities." .. statName .. ".diepool.low.count");
local lowDieTypesource = window.getDatabaseNode().createChild("qualities." .. statName .. ".diepool.low.type");
print("highDieCountsource NodeName outside if scope: " .. highDieCountsource.getNodeName());
print("highDieTypesource NodeName outside if scope: " .. highDieTypesource.getNodeName());

if prcQscore>0 then
while not diepoolref[prcQscore] do
prcQscore = prcQscore - 1;
end
print("Post While prcQscore: " .. prcQscore);
if diepoolref[prcQscore] then
if diepoolref[prcQscore]["highpool"] then
print("Highpool Processing");
if diepoolref[prcQscore]["highpool"]["count"] then
print("Diepool High Count: " .. diepoolref[prcQscore]["highpool"]["count"]);
print("Diepool High Typet: " .. diepoolref[prcQscore]["highpool"]["die"]);
print("highDieCountsource NodeName inside if scope: " .. highDieCountsource.getNodeName());
print("highDieTypesource NodeName inside if scope: " .. highDieTypesource.getNodeName());
highDieCountsource.setValue(diepoolref[prcQscore]["highpool"]["count"]);
highDieTypesource.setValue(diepoolref[prcQscore]["highpool"]["die"]);
print("highDieCountsource value inside if scope: " .. highDieCountsource.getValue());
print("highDieTypesource value inside if scope: " .. highDieTypesource.getValue());
else
print("-");
highDieCountsource.setValue("-");
highDieCountsource.setValue("-");
end
end
print("prcQscore: " .. prcQscore);
if diepoolref[prcQscore]["lowpool"] then
print("Lowpool Processing");
if diepoolref[prcQscore]["lowpool"]["count"] then
print("Diepool Low Count: " .. diepoolref[prcQscore]["lowpool"]["count"]);
print("Diepool Low Typet: " .. diepoolref[prcQscore]["lowpool"]["die"]);
print("lowDieCountsource NodeName inside if scope: " .. lowDieCountsource.getNodeName());
print("lowDieTypesource NodeName inside if scope: " .. lowDieTypesource.getNodeName());
lowDieCountsource.setValue(diepoolref[prcQscore]["lowpool"]["count"]);
lowDieTypesource.setValue(diepoolref[prcQscore]["lowpool"]["die"])
print("lowDieCountsource value inside if scope: " .. lowDieCountsource.getValue());
print("lowDieTypesource value inside if scope: " .. lowDieTypesource.getValue());
else
print("-");
lowDieCountsource.setValue("-");
lowDieCountsource.setValue("-");
end
end
end
end
end

The diepoolref table is defined later in the file and has been confirmed that its pulling all the data correctly.

drahkar
September 3rd, 2010, 00:55
Anyone have any thoughts or suggestions?

drahkar
September 3rd, 2010, 03:16
This is maddening. There is absolutely no reason this shouldn't be working that I can find. If anyone can offer some thoughts, I would most appreciate it.

Zeus
September 3rd, 2010, 09:56
Drahkar - I think it would be useful to see the whole file rather than just this function. Any chance you could post it up?

Is the code getting into the conditional blocks i.e. what output are you seeing on the console (print commands)?

Also is this code from within the script block for a windowclass or window control or is it from a LUA file?

drahkar
September 3rd, 2010, 10:16
Drahkar - I think it would be useful to see the whole file rather than just this function. Any chance you could post it up?


I can do that. Just a note, I left off the reference tables. But those are just normal nested array tables. I can add them if you'd like, but I'm holding off if I can just because they contain book data and I'm not comfortable posting it until the ruleset has been approved by the publishers.


local speciessource = nil;
local spectype = nil;
local qstat = nil;

function onInit()
speciessource = window.getDatabaseNode().getChild("details.species");
spectype = string.gsub(speciessource.getValue(), "(%(*)(%s*)(%)*)(%-*)", "");
qstat = stat[1];
print("Stat Variable Contents: " .. stat[1]);
setdiepool(getValue(), stat[1]);
speciessource.onUpdate = update;
if getValue() == 0 then
setValue(speciesqualityscore[spectype][qstat]);
end
end

function update()
speciessource = window.getDatabaseNode().getChild("details.species");
spectype = string.gsub(speciessource.getValue(), "(%(*)(%s*)(%)*)(%-*)", "");
qstat = stat[1];
setValue(speciesqualityscore[spectype][qstat]);
end

function setdiepool( prcQscore, statName)
print("prcQscore: " .. prcQscore);
print("statName: " ..statName);
local highDieCountsource = window.getDatabaseNode().createChild("qualities." .. statName .. ".diepool.high.count");
local highDieTypesource = window.getDatabaseNode().createChild("qualities." .. statName .. ".diepool.high.type");
local lowDieCountsource = window.getDatabaseNode().createChild("qualities." .. statName .. ".diepool.low.count");
local lowDieTypesource = window.getDatabaseNode().createChild("qualities." .. statName .. ".diepool.low.type");
print("highDieCountsource NodeName outside if scope: " .. highDieCountsource.getNodeName());
print("highDieTypesource NodeName outside if scope: " .. highDieTypesource.getNodeName());

if prcQscore>0 then
while not diepoolref[prcQscore] do
prcQscore = prcQscore - 1;
end
print("Post While prcQscore: " .. prcQscore);
if diepoolref[prcQscore] then
if diepoolref[prcQscore]["highpool"] then
print("Highpool Processing");
if diepoolref[prcQscore]["highpool"]["count"] then
print("Diepool High Count: " .. diepoolref[prcQscore]["highpool"]["count"]);
print("Diepool High Typet: " .. diepoolref[prcQscore]["highpool"]["die"]);
print("highDieCountsource NodeName inside if scope: " .. highDieCountsource.getNodeName());
print("highDieTypesource NodeName inside if scope: " .. highDieTypesource.getNodeName());
highDieCountsource.setValue(diepoolref[prcQscore]["highpool"]["count"]);
highDieTypesource.setValue(diepoolref[prcQscore]["highpool"]["die"]);
print("highDieCountsource value inside if scope: " .. highDieCountsource.getValue());
print("highDieTypesource value inside if scope: " .. highDieTypesource.getValue());
else
print("-");
highDieCountsource.setValue("-");
highDieCountsource.setValue("-");
end
end
print("prcQscore: " .. prcQscore);
if diepoolref[prcQscore]["lowpool"] then
print("Lowpool Processing");
if diepoolref[prcQscore]["lowpool"]["count"] then
print("Diepool Low Count: " .. diepoolref[prcQscore]["lowpool"]["count"]);
print("Diepool Low Typet: " .. diepoolref[prcQscore]["lowpool"]["die"]);
print("lowDieCountsource NodeName inside if scope: " .. lowDieCountsource.getNodeName());
print("lowDieTypesource NodeName inside if scope: " .. lowDieTypesource.getNodeName());
lowDieCountsource.setValue(diepoolref[prcQscore]["lowpool"]["count"]);
lowDieTypesource.setValue(diepoolref[prcQscore]["lowpool"]["die"])
print("lowDieCountsource value inside if scope: " .. lowDieCountsource.getValue());
print("lowDieTypesource value inside if scope: " .. lowDieTypesource.getValue());
else
print("-");
lowDieCountsource.setValue("-");
lowDieCountsource.setValue("-");
end
end
end
end
end



Is the code getting into the conditional blocks i.e. what output are you seeing on the console (print commands)?

From what I can see, everything is outputting from the prints correctly right up until it errors for a nil value because the 'print("highDieCountsource value inside if scope: " .. highDieCountsource.getValue());' is getting a blank datanode.


Also is this code from within the script block for a windowclass or window control or is it from a LUA file?

This is in a Lua file which is pointed to from a numberfield control.

Zeus
September 3rd, 2010, 10:59
What happens if you try assigning the value from the nested array tables to an intermediate variable and then use the variable with setValue().

e.g.


local strval = diepoolref[prcQscore]["highpool"]["count"];
highDieCountsource.setValue(strval);

print(strval);
print(highDieCountsource.getValue());

drahkar
September 3rd, 2010, 11:33
Tested and unfortunately the same result. It's a curiously weird problem.

Zeus
September 3rd, 2010, 11:56
So from my example when you print the variable you get a value but when you print the getValue() from the control you get nil?

EDIT: Also, What type is highDieCountsource and the other nodes your setting, have you tried forcing the node type during the createChild() calls? You maybe trying to assign a string to a number etc.

EDIT 2: I'm on IRC if that makes it easier. :)

drahkar
September 3rd, 2010, 13:12
To IRC! :D

drahkar
September 3rd, 2010, 13:23
And that hurdle is solved. With DrZeuss' help we were able to narrow it down to improperly set Node Types.