table help

This is an example code, this is not my actual code.

table = {} tableNum = 1 table[1] = "test" function printer(param) print(param) end function main() printer(table[tableNum]) end main()

I would like the printer function to be called with this parameter but it doesn’t work. Please help.

You should not use “table” as a variable.  Its a global object of table functions, though what you did should work.  I did a quick test and the code works.  However, there is an issue going on that we are looking to solve where it’s possible (on Mac’s) that the output doesn’t get written to the terminal window correctly.

Can you tell me more about your environment:

OS and version?

Corona SDK version?

Your actual could would be helpful too.  You really can’t post some sample code, tell us yours is different and ask “why doesn’t it work?” if the bug is in your code.

Rob

Hi.  The sample you supplied had a couple of problems and since it isn’t your original code it is hard to know if they existed there too:

  • Use of globals when locals make more sense.
  • Use of keyword ‘table’ as variable name.

Try this:

local myTable = {} local tableNum = 1 myTable[1] = "test" local function myPrinter(param) print(param) end local function main() myPrinter( myTable[tableNum] ) end main()

Thanks guys for taking the time to answer. I finally was able to fix the bug on my real code. I will think of posting the whole code next time. Thanks a lot.

You should not use “table” as a variable.  Its a global object of table functions, though what you did should work.  I did a quick test and the code works.  However, there is an issue going on that we are looking to solve where it’s possible (on Mac’s) that the output doesn’t get written to the terminal window correctly.

Can you tell me more about your environment:

OS and version?

Corona SDK version?

Your actual could would be helpful too.  You really can’t post some sample code, tell us yours is different and ask “why doesn’t it work?” if the bug is in your code.

Rob

Hi.  The sample you supplied had a couple of problems and since it isn’t your original code it is hard to know if they existed there too:

  • Use of globals when locals make more sense.
  • Use of keyword ‘table’ as variable name.

Try this:

local myTable = {} local tableNum = 1 myTable[1] = "test" local function myPrinter(param) print(param) end local function main() myPrinter( myTable[tableNum] ) end main()

Thanks guys for taking the time to answer. I finally was able to fix the bug on my real code. I will think of posting the whole code next time. Thanks a lot.