SniperDM
June 8th, 2007, 10:11
I'm taking my first baby steps towards learning lua and how it applies to fantasygrounds. It's slow going, but I've run into a little snag concerning the print function and its proper use. I guess a lot of it has to do with the syntax of how to call variables in a table, but let me try to explain.
Basically, when I try to print a variable to the console for debugging purposes, I seem to return a (null) value no matter what I do when the variable is contained in a table of some sort. Here's the exact code block in questions.
-- Name
for k, v in ipairs(getWindows()) do
if source.getChild("name") then
newentry.name.setValue(source.getChild("name").getValue());
print(k)
print(newentry.name)
end
end
This is meant to be inserted into the combattracker.lua file, in the name section of the addNPC function.
When I run FG and add an NPC to the combat tracker, this is the output in the console window, assuming I already have four other entries.
Script Notice: 1
Script Notice: (null)
Script Notice: 2
Script Notice: (null)
Script Notice: 3
Script Notice: (null)
Script Notice: 4
Script Notice: (null)
Script Notice: 5
Script Notice: (null)
Now I would have thought that the (null) values should instead be displaying the name of the NPC I just added to the tracker. (A silly thing to check, but this is for testing/learning purposes only). Furthermore, when I quit FG 2 after seeing all this, I get an error message stating. . .
The instruction at "0x0045xx60" referenced memory at "0x00000000". The memory could not be "read".
So quite frankly, I'm stumped, and I can't really fathom learning anything else until I understand what the heck I'm doing wrong here, or if somehow by chance something's wrong with the print function instead. Would appreciate any info on this. Thanks.
Basically, when I try to print a variable to the console for debugging purposes, I seem to return a (null) value no matter what I do when the variable is contained in a table of some sort. Here's the exact code block in questions.
-- Name
for k, v in ipairs(getWindows()) do
if source.getChild("name") then
newentry.name.setValue(source.getChild("name").getValue());
print(k)
print(newentry.name)
end
end
This is meant to be inserted into the combattracker.lua file, in the name section of the addNPC function.
When I run FG and add an NPC to the combat tracker, this is the output in the console window, assuming I already have four other entries.
Script Notice: 1
Script Notice: (null)
Script Notice: 2
Script Notice: (null)
Script Notice: 3
Script Notice: (null)
Script Notice: 4
Script Notice: (null)
Script Notice: 5
Script Notice: (null)
Now I would have thought that the (null) values should instead be displaying the name of the NPC I just added to the tracker. (A silly thing to check, but this is for testing/learning purposes only). Furthermore, when I quit FG 2 after seeing all this, I get an error message stating. . .
The instruction at "0x0045xx60" referenced memory at "0x00000000". The memory could not be "read".
So quite frankly, I'm stumped, and I can't really fathom learning anything else until I understand what the heck I'm doing wrong here, or if somehow by chance something's wrong with the print function instead. Would appreciate any info on this. Thanks.