Jump to content




listen:6: attempt to concatenate a string and nil


5 replies to this topic

#1 PineapplExplosive

  • New Members
  • 1 posts

Posted 28 February 2016 - 05:23 PM

i'm new to this and can't seem to understand what does this mean?

the code is very simple


local event, x, y = os.pullEvent("mouse_click")
if event == "mouse_click" then

print("Event: "..event)
print("X: "..x)
print("Y: "..y)
end

and it only happens when i have a third variable like "y" because i tried with local event and x and it worked fine

#2 Creator

    Mad Dash Victor

  • Members
  • 2,168 posts
  • LocationYou will never find me, muhahahahahaha

Posted 28 February 2016 - 06:15 PM

1. You forgot the button: event, button, x, y

2. A small modification I make to avoid error like this:

local event, button, x, y = os.pullEvent("mouse_click")
if event == "mouse_click" then
  print("Event: "..event)
  print("X: ", x)
  print("Y: ", y)
end

3. Event will always be "mouse_click" so no need to check.
4. Also, x and y should be numbers, not strings and you cannot concat strings with numbers.

#3 Dragon53535

  • Members
  • 973 posts
  • LocationIn the Matrix

Posted 28 February 2016 - 06:53 PM

Well yes you can, and his error wasn't "attempt to concatenate string and number" it was "attempt to concatenate string and nil" which means for some reason the 3rd return value for his os.pullEvent call returned nil.
Also, yes, that is the order of the return values, in his case, his x was button, and y was x. However for whatever reason his x coordinate was nil.

Before it errored Pineappl, what did it print? It should of printed something like
mouse_click
1

Edited by Dragon53535, 28 February 2016 - 06:55 PM.


#4 TYKUHN2

  • Members
  • 210 posts
  • LocationSomewhere in this dimension... I think.

Posted 28 February 2016 - 07:49 PM

Numbers and strings are interchangable except if it is a string with letters, only then is it interchangable in one direction. (To string) There are also other interchangable things. Numerical arrays and named arrays for example.

#5 MKlegoman357

  • Members
  • 1,170 posts
  • LocationKaunas, Lithuania

Posted 28 February 2016 - 08:44 PM

View PostTYKUHN2, on 28 February 2016 - 07:49 PM, said:

Numerical arrays and named arrays for example.

In Lua there are no arrays, there are only tables.

#6 TYKUHN2

  • Members
  • 210 posts
  • LocationSomewhere in this dimension... I think.

Posted 28 February 2016 - 08:58 PM

Array = Table which is essentially what I was getting at.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users