strange error

Hello,

I have encountered a very strange and funny error, I hope someone can figure it out.

I pass a number to a function and use that number to access a value from a table, but the number which i pass becomes nil in the process.

Take a look at the following code.

local players = {} local bots = {} bots[1] = {name = "bot1", country = "USA"} bots[2] = {name = "bot2", country = "Russia"} local function test(num) local newCircle = display.newCircle(10,10,10) --strangely the "num" becomes nil in the following line newCircle.id = bots[num].name players[newCircle.id] = newCircle end test(1)

I think the problem is that the .id variable for your bots tables isn’t defined. I did this and it worked fine:

local players = {} local bots = {} bots[1] = {name = "bot1", country = "USA"} bots[2] = {name = "bot2", country = "Russia"} bots[1].id = "testing var" local function test(num) local newCircle = display.newCircle(10,10,10) --strangely the "num" becomes nil in the following line newCircle.id = bots[num].id players[newCircle.id] = newCircle end test(1)

No, it was supposed to be .name, i mistakenly put .id

I corrected the code in my first post, now if you try you will get nil value

frustrating error, please help :confused:

Someone please? i can’t figure it out…

I think the problem is that the .id variable for your bots tables isn’t defined. I did this and it worked fine:

local players = {} local bots = {} bots[1] = {name = "bot1", country = "USA"} bots[2] = {name = "bot2", country = "Russia"} bots[1].id = "testing var" local function test(num) local newCircle = display.newCircle(10,10,10) --strangely the "num" becomes nil in the following line newCircle.id = bots[num].id players[newCircle.id] = newCircle end test(1)

No, it was supposed to be .name, i mistakenly put .id

I corrected the code in my first post, now if you try you will get nil value

frustrating error, please help :confused:

Someone please? i can’t figure it out…