Jump to content




[Error][SOLVED] attempt to compare string with number expected, got string


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

#1 unobtanium

  • Members
  • 505 posts

Posted 28 January 2013 - 05:23 AM

Hello everybody,
i know this sounds like the good and old tonumber(read()) mistake, but it isnt.
I am programming an menu for a logistic storage. In this menu you can select an item by pressing left and right key.
I marked it in the code.
The problem is that if i press the left button i get
132: attempt to compare string with number expected, got string
If i press the left button i get
129: attempt to perform arithmetic __add on string and number

It should check the variable "id" and increase and decrease the variable by one. The program thinks id is a string, but i want a number. I never said that it should be a string in my oppinion. I think it messed it up after it used the getItemName() function.
Spoiler

The first time i open the menu it worked. But if i use the right or left key it gives me the error.

Posted Image


Thank you for your help :D
UNOBTANIUM

#2 Orwell

    Self-Destructive

  • Members
  • 1,091 posts

Posted 28 January 2013 - 05:27 AM

You have this in the function runMenu:
local id, key = os.pullEvent("key")
So you simply override the variable 'id' with the event type, which is a string...
change that to
local _, key = os.pullEvent("key")
or something and you'll be fine :)

#3 unobtanium

  • Members
  • 505 posts

Posted 28 January 2013 - 05:30 AM

Oh good god...
Wow. I totally forgot about that one :D
Thank you :D





2 user(s) are reading this topic

0 members, 2 guests, 0 anonymous users