Jump to content




"index expected, got nil" without an array anywhere


  • You cannot reply to this topic
4 replies to this topic

#1 Hydrotronics

  • Members
  • 131 posts
  • LocationThe hall of 1000 monkeys and only 1 typewriter

Posted 24 February 2016 - 06:46 PM

Yet another problem with my Interaction API and this time it's complaining about me using a table term when I am not using any tables.
This is one line 3 of the code, click the link above to go to the pastebin.
This used to work, but for some reason doesn't... and it started ever since I implemented interaction.drawButton() which is further down.

~Hydro

#2 Sewbacca

  • Members
  • 450 posts
  • LocationStar Wars

Posted 24 February 2016 - 06:57 PM

You have to create a list, before you can declare functions in it:
prognam = shell.getRunningProgram()
screenX, screenY = term.getSize()
_G["interact"] = {} --You haven't use _G, if you want to use your API just in the normal shell or higher instances.
function interact.centertext(text,ypos)
  local char = tostring(text)
  local chars = string.len(char)
  local hchars = math.floor(chars / 2)
  local xpos = math.ceil((screenX / 2) - hchars)
  term.setCursorPos(xpos,ypos)
  print(text)
end


#3 Hydrotronics

  • Members
  • 131 posts
  • LocationThe hall of 1000 monkeys and only 1 typewriter

Posted 24 February 2016 - 07:03 PM

Ta :)

is this because i set it in interact.(funcname)?
I'm usually used to just making function names so this is the first time i've actually added a catagory to the functions.

#4 Sewbacca

  • Members
  • 450 posts
  • LocationStar Wars

Posted 24 February 2016 - 07:07 PM

View PostHydrotronics, on 24 February 2016 - 07:03 PM, said:

Ta :)

is this because i set it in interact.(funcname)?
I'm usually used to just making function names so this is the first time i've actually added a catagory to the functions.
Yes, you add with interact[string name] a value into the table interact, so you have to declare the table before.
Tables are very powerful types (click here for more information).

Edited by Sewbacca, 24 February 2016 - 07:13 PM.


#5 KingofGamesYami

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

Posted 24 February 2016 - 07:07 PM

The syntax a.b is equivalent to a[ "b" ]. In other words, it accesses the table a with the key b.

Also, do not confuse tables with lists. They are tables. There are no lists in Lua.

Edited by KingofGamesYami, 24 February 2016 - 07:08 PM.






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users