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

[Error]Number Expected, got string

Started by Mailmanq!, 12 March 2013 - 11:05 AM
Mailmanq! #1
Posted 12 March 2013 - 12:05 PM
When I run my program, it give me an error on line #58, bad argument : number expected, got string, I have no idea why. Can you?
Code: https://github.com/n...ster/rtos/rtgui
LuaEclipser #2
Posted 12 March 2013 - 12:09 PM
no one is going to github just to look at your program. give what wrong, where you think what wrong. dont just send everyone your whole program in github
Mailmanq! #3
Posted 12 March 2013 - 12:11 PM
no one is going to github just to look at your program. give what wrong, where you think what wrong. dont just send everyone your whole program in github
I sent the exact program with the error, and I said the error.
SuicidalSTDz #4
Posted 12 March 2013 - 12:19 PM
no one is going to github just to look at your program. give what wrong, where you think what wrong. dont just send everyone your whole program in github
It doesn't matter where he sends us, as long as the code is visible. He also stated the error and the line. Please read before posting.



no one is going to github just to look at your program
I just went there; your statement is invalid
LuaEclipser #5
Posted 12 March 2013 - 12:21 PM
btw, best to put your menu in a table, and use a print table function, like this for your menu


[size=4]Menu = {
[size=4]"X------X",
[size=4]"X		X",
[size=4]"X------X"
}

[size=4]function printTable(table)

for i=1, #table do
print(table[i])
end
end
printTable(Menu)
UNTESTED; SHOULD WORK
small version of menu
NOTE: ignore the [font][/font]
SuicidalSTDz #6
Posted 12 March 2013 - 12:25 PM
btw, best to put your menu in a table, and use a print table function, like this for your menu


[size=4]Menu = {[/size]
[size=4]"X------X",[/size]
[size=4]"X		X",[/size]
[size=4]"X------X"[/size]
[size=4]}[/size]

[size=4]function printTable(table)[/size]

for i=1, #table do
print(table[i])
end
end
UNTESTED; SHOULD WORK
small version of menu

printTable(Menu)
Not a fan of using arrays to read the contents of a table. Also that would not work since you are overriding the table api with a table named 'table'.
for k,v in pairs(menu) do
 print(v)
end
This is also off topic. You are avoiding the error at hand and simply went off and are now lecturing him about how he should make his program. Let's focus on the problem.
MysticT #7
Posted 12 March 2013 - 02:09 PM
Well, the error is that you got the arguments for string.rep backwards, the string should be the first argument and the number the second.

Not a fan of using arrays to read the contents of a table.
Actually, iterating using a counter (like for i = 1, #tbl do) is faster than using pairs (it's too small to notice, but for larger tables - really larger tables - you may notice it). Also, pairs doesn't ensure that the table will be iterated in order, so it would be better to use ipairs.
SuicidalSTDz #8
Posted 12 March 2013 - 02:18 PM
I guess since ipairs returns three values (an iterator function, the table, and 0), it would be the superior choice, now wouldn't it. ^_^/> I always take ipairs for granted :P/> I still don't like using an array to iterate over the table. But meh, that's just me ;)/>
Mailmanq! #9
Posted 12 March 2013 - 02:36 PM
Well, the error is that you got the arguments for string.rep backwards, the string should be the first argument and the number the second.
Wow, I was editing a copy of this program when I fixed that :P/> thanks