STAR TREK 2d20
  1. #1

    Debugging... print function?

    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.

    Code:
    	-- 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.
    Code:
    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. . .
    Quote Originally Posted by Error message
    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.

  2. #2
    Quote Originally Posted by SniperDM
    Code:
    	-- 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
    Code:
    print(newentry.name.getValue());
    Also, pretty sure the print function needs a semicolon at end of line.

  3. #3
    Quote Originally Posted by joshuha
    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."

  4. #4
    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?

  5. #5
    Quote Originally Posted by sunbeam60
    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

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
FG Spreadshirt Swag

Log in

Log in