Jump to content




[Error]Number Expected, got string


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

#1 Mailmanq!

  • Members
  • 123 posts
  • LocationI am omnipresent... DUH

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

#2 LuaEclipser

  • Banned
  • 220 posts
  • LocationCleveland, Ohio

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

#3 Mailmanq!

  • Members
  • 123 posts
  • LocationI am omnipresent... DUH

Posted 12 March 2013 - 12:11 PM

View PostLuaEclipser, on 12 March 2013 - 12:09 PM, said:

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.

#4 SuicidalSTDz

    Permutator of Strings

  • Members
  • 1,308 posts
  • LocationPennsylvania

Posted 12 March 2013 - 12:19 PM

View PostLuaEclipser, on 12 March 2013 - 12:09 PM, said:

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.



View PostLuaEclipser, on 12 March 2013 - 12:09 PM, said:

no one is going to github just to look at your program
I just went there; your statement is invalid

#5 LuaEclipser

  • Banned
  • 220 posts
  • LocationCleveland, Ohio

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 [size=whatever]

#6 SuicidalSTDz

    Permutator of Strings

  • Members
  • 1,308 posts
  • LocationPennsylvania

Posted 12 March 2013 - 12:25 PM

View PostLuaEclipser, on 12 March 2013 - 12:21 PM, said:

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.

#7 MysticT

    Lua Wizard

  • Members
  • 1,597 posts

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.

View PostSuicidalSTDz, on 12 March 2013 - 12:25 PM, said:

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.

#8 SuicidalSTDz

    Permutator of Strings

  • Members
  • 1,308 posts
  • LocationPennsylvania

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 ;)

#9 Mailmanq!

  • Members
  • 123 posts
  • LocationI am omnipresent... DUH

Posted 12 March 2013 - 02:36 PM

View PostMysticT, on 12 March 2013 - 02:09 PM, said:

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





2 user(s) are reading this topic

0 members, 2 guests, 0 anonymous users