PDA

View Full Version : Debugging... print function?



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.

joshuha
June 8th, 2007, 13:59
-- 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.



Have you tried

print(newentry.name.getValue());

Also, pretty sure the print function needs a semicolon at end of line.

sunbeam60
June 8th, 2007, 14:34
Also, pretty sure the print function needs a semicolon at end of line.

Programming in Lua, 1.1 Chunks: "A semicolon may optionally follow any statement."

SniperDM
June 8th, 2007, 20:16
print(newentry.name.getValue());
Ah... of course. getValue! Proper syntax done always be'd my worsted subjects.

Still, I keep getting that memory error every time I try to open the console and then close the program, which is why I originally posted to house of healing instead of the workshop, even though my output is fine now. Is anyone else experiencing anything similar?

joshuha
June 8th, 2007, 21:28
Programming in Lua, 1.1 Chunks: "A semicolon may optionally follow any statement."

Cool. I could have sworn I have had errors about missing semi-colons but maybe I am getting my day job confused with my hobby :)