Jump to content




index expected, instead got nil

help networking computer

9 replies to this topic

#1 eniallator

  • Members
  • 56 posts

Posted 17 January 2016 - 11:15 PM

I've been working on a new feature for my Remote/Control programs and have tried to implement it into my control program. the error im running into is this: mControl:135: index expected, instead got nil

Here is the pastebin for the program and Here is the plugin its trying to load. I also have a couple of screenshots Here (the reason why it says 137 in the screenshot is because of the 2 prints i have added before it).

#2 KingofGamesYami

  • Members
  • 3,002 posts
  • LocationUnited States of America

Posted 18 January 2016 - 12:04 AM

Basically you're trying to index a value which isn't a table (instead, it's nil).

Line 135:
_G[tabName][key]

_G clearly isn't nil.

_G[ tabName ] could very well be nil. I would consider using a print on this, to check when it's nil and why.

#3 eniallator

  • Members
  • 56 posts

Posted 18 January 2016 - 12:20 AM

View PostKingofGamesYami, on 18 January 2016 - 12:04 AM, said:

Basically you're trying to index a value which isn't a table (instead, it's nil).

Line 135:
_G[tabName][key]

_G clearly isn't nil.

_G[ tabName ] could very well be nil. I would consider using a print on this, to check when it's nil and why.

did you see the imgur link to the ingame screenshots i posted aswell? i've printed mergeTab, tabName, key and value and they all are what they should be

#4 Dragon53535

  • Members
  • 971 posts
  • LocationIn the Matrix

Posted 18 January 2016 - 12:36 AM

Well obviously not if it's erroring on you. It's best to make sure, add in an if statement.

if _G[tabName] then
  _G[tabName][key] = value
else
  print("Aww shucks, it's nil")
end

Edited by Dragon53535, 18 January 2016 - 12:38 AM.


#5 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 18 January 2016 - 06:51 AM

That's odd, are you sure it's not line 134 throwing the error? That particular message isn't something I'd expect from that particular line, though pairs() could throw it.

#6 eniallator

  • Members
  • 56 posts

Posted 18 January 2016 - 08:59 AM

View PostDragon53535, on 18 January 2016 - 12:36 AM, said:

Well obviously not if it's erroring on you. It's best to make sure, add in an if statement.

if _G[tabName] then
  _G[tabName][key] = value
else
  print("Aww shucks, it's nil")
end

just tried that and its always going to the else statement and not the code in the if.

View PostBomb Bloke, on 18 January 2016 - 06:51 AM, said:

That's odd, are you sure it's not line 134 throwing the error? That particular message isn't something I'd expect from that particular line, though pairs() could throw it.

well its saying the line after so if it means the line before then yes but wouldn't that error/nil when i tried to print it?

#7 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 18 January 2016 - 09:09 AM

Yeah, you're quite right, it's because you never put the tables you're trying to index into _G.

Defining them as global tables (as you do around line 38) doesn't achieve that, at least, not within ComputerCraft. Each system has a global environment table that's separate to _G. If you want to stick something in _G, specify that that's where you want it to go.

Which brings up the question, why would you want to stick it them _G? Why not just make them subtables of something local to your script?

#8 eniallator

  • Members
  • 56 posts

Posted 18 January 2016 - 09:15 AM

View PostBomb Bloke, on 18 January 2016 - 09:09 AM, said:

Yeah, you're quite right, it's because you never put the tables you're trying to index into _G.

Defining them as global tables (as you do around line 38) doesn't achieve that, at least, not within ComputerCraft. Each system has a global environment table that's separate to _G. If you want to stick something in _G, specify that that's where you want it to go.

Which brings up the question, why would you want to stick it them _G? Why not just make them subtables of something local to your script?

How would i specify thats where i want it to go? and im not sure what you mean by that last bit :P

Edited by eniallator, 18 January 2016 - 09:50 AM.


#9 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 18 January 2016 - 11:35 AM

View Posteniallator, on 18 January 2016 - 09:15 AM, said:

How would i specify thats where i want it to go?

Instead of:

status = {upload = 1, download = 1, filelist = 1, redstone = 1}

... you'd do:

_G.status = {upload = 1, download = 1, filelist = 1, redstone = 1}

View Posteniallator, on 18 January 2016 - 09:15 AM, said:

and im not sure what you mean by that last bit :P

local myTable = {}
myTable.status = {upload = 1, download = 1, filelist = 1, redstone = 1}


#10 eniallator

  • Members
  • 56 posts

Posted 18 January 2016 - 09:11 PM

View PostBomb Bloke, on 18 January 2016 - 11:35 AM, said:

View Posteniallator, on 18 January 2016 - 09:15 AM, said:

How would i specify thats where i want it to go?

Instead of:

status = {upload = 1, download = 1, filelist = 1, redstone = 1}

... you'd do:

_G.status = {upload = 1, download = 1, filelist = 1, redstone = 1}

View Posteniallator, on 18 January 2016 - 09:15 AM, said:

and im not sure what you mean by that last bit :P

local myTable = {}
myTable.status = {upload = 1, download = 1, filelist = 1, redstone = 1}

i made another solution for the problem and Here is the result of it, Thank you so much for the help though, i don't think i was even close to finding the solution ;)





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users