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

listen:6: attempt to concatenate a string and nil

Started by PineapplExplosive, 28 February 2016 - 04:23 PM
PineapplExplosive #1
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
Creator #2
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.
Dragon53535 #3
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 on 28 February 2016 - 05:55 PM
TYKUHN2 #4
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.
MKlegoman357 #5
Posted 28 February 2016 - 08:44 PM
Numerical arrays and named arrays for example.

In Lua there are no arrays, there are only tables.
TYKUHN2 #6
Posted 28 February 2016 - 08:58 PM
Array = Table which is essentially what I was getting at.