Right so, I'm trying to make a simple GUI and am bad at using tables, my error is on line 43 (menus[curmenu].drawfunc()) and it says attempt call nill... I realise I'm probably choosing the wrong key or something but the problem is I don't know the syntax for calling stuff from tables no matter how many tutorials I read. So what's the syntax in this particular case?
Newb with tables help.
#1
Posted 29 September 2012 - 03:56 PM
Right so, I'm trying to make a simple GUI and am bad at using tables, my error is on line 43 (menus[curmenu].drawfunc()) and it says attempt call nill... I realise I'm probably choosing the wrong key or something but the problem is I don't know the syntax for calling stuff from tables no matter how many tutorials I read. So what's the syntax in this particular case?
#2
Posted 29 September 2012 - 04:53 PM
sirdabalot, on 29 September 2012 - 03:56 PM, said:
Right so, I'm trying to make a simple GUI and am bad at using tables, my error is on line 43 (menus[curmenu].drawfunc()) and it says attempt to call nill. I realise I'm probably choosing the wrong key or something but the problem is I don't know the syntax for calling stuff from tables no matter how many tutorials I read. So whats the syntax in this particular case?
i can only state the obvious because i never used stacking tables but if you want to call an string you have to put the "" aroud it like this write(menus["main"].options[i])
#3
Posted 29 September 2012 - 04:58 PM
Kolpa, on 29 September 2012 - 04:53 PM, said:
sirdabalot, on 29 September 2012 - 03:56 PM, said:
Right so, I'm trying to make a simple GUI and am bad at using tables, my error is on line 43 (menus[curmenu].drawfunc()) and it says attempt to call nill. I realise I'm probably choosing the wrong key or something but the problem is I don't know the syntax for calling stuff from tables no matter how many tutorials I read. So whats the syntax in this particular case?
i can only state the obvious because i never used stacking tables but if you want to call an string you have to put the "" aroud it like this write(menus["main"].options[i])
wait nevermind this should be the real error:
term.clear()
term.setCursorPos(1,1)
curmenu = "main"
menus = {
main = {
options = {
"Numbers",
"Letters",
"Quit",
},
drawfunc = drawMain
},
numbers = {
options = {
"1",
"2",
"3",
},
},
letters = {
options = {
"A",
"B",
"C",
},
}
}
-- Main Program
while true do
menus.drawfunc() --drawfunc is not in the main table
end
#4
Posted 29 September 2012 - 05:09 PM
EDIT: Wait, are you sure it's not in the main table? According to notepad++ it is.
#5
Posted 29 September 2012 - 06:35 PM
then try
menus[1].drawfunc()
and 1. of all try declaring the function before you rename it
#6
Posted 29 September 2012 - 07:31 PM
Kolpa, on 29 September 2012 - 06:35 PM, said:
then try
menus[1].drawfunc()
and 1. of all try declaring the function before you rename it
After a bit of testing I found that functions probably don't need to be placed in a different order, but anyway if I put the function above the table it gives me an error at write(menus[main].options[i]). Furthermore if i try menus[1].drawfunc() it gives me attempt to index ? a nill value.
BTW on the opening post I said it gives me attempts to call nill error, it was actually attempt to index ? a nill value.
EDIT: I lied, by changing it to menus[1].drawfunc() it gave me attempt to index ? a nill value
#7
Posted 29 September 2012 - 08:38 PM
write(menus[main].options[i]) -- should be: write(menus["main"].options[i]) -- or write(menus.main.options[i])
#8
Posted 29 September 2012 - 08:59 PM
MysticT, on 29 September 2012 - 08:38 PM, said:
write(menus[main].options[i]) -- should be: write(menus["main"].options[i]) -- or write(menus.main.options[i])
Okay, so let me clear one last thing up. When do I use a ., when do I use [] and when do enclose in quotes?
#9
Posted 29 September 2012 - 09:51 PM
t["key"] t.keyIt will get the value stored on the table with the string "key" as key.
This:
t[key]will get the value in the table with the content of the variable "key" as key. So, if the variable key contains the number 2, it would be like doing
t[2]
#10
Posted 29 September 2012 - 10:05 PM
MysticT, on 29 September 2012 - 09:51 PM, said:
t["key"] t.keyIt will get the value stored on the table with the string "key" as key.
This:
t[key]will get the value in the table with the content of the variable "key" as key. So, if the variable key contains the number 2, it would be like doing
t[2]
And it works with numbers too? So if I had table t and had a value at index 3 I could use:
t.3
As well as:
t[3]
#11
Posted 29 September 2012 - 10:12 PM
2 user(s) are reading this topic
0 members, 2 guests, 0 anonymous users











