How do I get Accelerometer x,y,z values? Compiler says it's a single number

I think the documentation call them tuples, but I don't think they are actually tuples.

You just need to know that in lua a function can return multiple values which is extremely handy.

function getPosition()
  return x, y
end

You can also assign multiple values at once
x, y = 10, 20

and so you can catch all return values in one go
x, y = getPosition()

or even passing them as an multiple argument in a function call
image:draw( getPosition() )

but only for the last arguments
print( getPosition(), "foobar" ) -- will print x and "foobar", y will be skiped
print( "foobar", getPosition() ) -- will print "foobar", x and y

If you want to get all the return values in a single object you can do
object = { getPosition() }
or
object = table.pack( getPosition() ) -- get an extra 'n' member for the number of fields

and you can do the opposite and call table.unpack() to get a sequence of return values

6 Likes