173 posts
Location
The 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
463 posts
Location
Star 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
173 posts
Location
The 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.
463 posts
Location
Star Wars
Posted 24 February 2016 - 07:07 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.
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 on 24 February 2016 - 06:13 PM
3057 posts
Location
United 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 on 24 February 2016 - 06:08 PM