This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Lewis10134's profile picture

[LUA] I don't know what is wrong

Started by Lewis10134, 15 November 2012 - 05:14 AM
Lewis10134 #1
Posted 15 November 2012 - 06:14 AM
I have attempted to create a GUI program but when i call my 'option' function only the first time it will enter store the variable into my table. The other times it doesn't enter nor does it overwrite the original variable in the table.

http://pastebin.com/UNN3vdva

My program is there and any help as to my problem is much appreciated.
Fiery Arcanine #2
Posted 15 November 2012 - 07:05 AM
Is it supposed to say hight? It's height

Edit: 2nd line
Lewis10134 #3
Posted 15 November 2012 - 07:47 AM
Thank you, i must have overlooked that, i have updated the code as to make it easier to read and fix the spelling errors. Again, any help as to my problem would be much appreciated.
remiX #4
Posted 15 November 2012 - 09:28 AM
You call detect() after your write(progs[1], progs[2]) etc. Is that not the problem?
Lewis10134 #5
Posted 15 November 2012 - 10:59 AM
No, I believe the problem is that the first time I run the option function it places 'pos' in the 'progs' table in the 'optno' position (at that time 1) but when it runs again for the second option (optno is now equal to 2) it fails to add the pos to the second position in the table; it fails to add anything to the table as a whole. Is it possible to do what i'm trying (insert into a table using local variables from a function) and if so what am I doing incorrectly. The printing of [1] and [2] from the table is merely there as that is my evidence that the second variable is not being added to the table. The detect function is what causes the error in my program as it cant find a second position in the 'progs' table.
Lyqyd #6
Posted 15 November 2012 - 11:17 AM
Try declaring the progs table as an empty table and not specifying the position to insert the value in the table.insert call.
Lewis10134 #7
Posted 15 November 2012 - 11:38 AM
I'm still having the problem of the variable 'pos' not being entered in the table. when printing progs[1] and [2] only the first value is shown which leads me to believe that the variable is still not being stored in the table. I tried using an empty table and not specifying the position in the insert call but i'm still having the same problem.
immibis #8
Posted 15 November 2012 - 11:50 AM
Write only prints the first argument.