• Strange error in a register function
    7 replies, posted
Alright so let me just pull up ye olde code. [Lua]local item = {} --define a local table that we can use to --later define in a stored table...not here. item.className = "rimm_357" --class name to use as a key for the table mentioned earlier item.modelPath = "blahblahblah" --357 model path registerNewItem( item ) --register the item so it stays in the --stored item table for later use itemTable = {} --create an item table to store item data in function registerNewItem( item ) itemTable[item.className] = item --store our local end --tables containing variables for our items by classname for k, v in ipairs (itemTable["rimm_357"]) do --loop through the print(k) --table of rimm_357 and print it's keys. end[/Lua] And I'm using lua edit to compile and run my program, and I get the error of "string(0)". The comments should be pretty self explanatory of what I was trying to accomplish. Help would be much appreciated.
Use pairs, not ipairs. ipairs is for iteration over numerically indexed tables.
Alright, it's still broken, I hope your as fast as your first post. Edit: Still getting same error, but ipairs changed to pairs.
Just tested code on [url=http://www.lua.org/cgi-bin/demo]this[/url] and it worked fine (I needed to define the registerNewItem function before it was called, maybe this is the problem?)
Explain what you mean by 'define' new function.
I moved this part of the code to the top, so it is before the part where it is called. [lua]function registerNewItem( item ) itemTable[item.className] = item --store our local end --tables containing variables for our items by classname[/lua]
Oh, so the register could would have to be at the top, let me try compiling on lua edit again. Btw thanks so much for your patience and help. Edit: Noice it works, +1 awesome for you.
[QUOTE=connorclockwise;21471684]Oh, so the register could would have to be at the top, let me try compiling on lua edit again. Btw thanks so much for your patience and help. Edit: Noice it works, +1 awesome for you.[/QUOTE] :iia:
Sorry, you need to Log In to post a reply to this thread.