Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
Printing positions — Gideros Forum

Printing positions

DikkesnoekDikkesnoek Member
edited October 2012 in General questions
I just discovered a weird printing issue. When I do:

print(testSprite:getPosition(), testBody:getPosition())

It will give for example: 188, 188, 489.

When I do:

print(testSprite:getPosition())
print(testBody:getPosition())

I will get as expected:

188, 489
188, 489

Why is the first Y value in the first example not printed?

Regards,

Marc

Comments

  • atilimatilim Maintainer
    edited October 2012
    It's a Lua thing. For example, if you execute this code
    local function foo1()
    	return "a", "b", "c"
    end
     
    local function foo2()
    	return 1, 2, 3
    end
     
    local function foo3()
    	return "x", "y", "z"
    end
     
    print(foo1(), foo2(), foo3())
    you'll get first return value of foo1 and first return value of foo2 and all return values of foo3:
    a 1 x y z
    It's described here a little bit more: http://www.lua.org/pil/5.1.html
    When we use a call as an expression, Lua keeps only the first result. We get all results only when the call is the last (or the only) expression in a list of expressions


    Likes: OZApps

    +1 -1 (+1 / -0 )Share on Facebook
  • Thanks Atilim.

    I found another issue why I've got wierd errors and values. For bodies you'll
    need to use getPosition() instead of getX() and getY(). Why is that? You can
    use getPosition() for sprites and bodies.

    Regards,

    Marc
  • @Dikkesnoek because there was a method getPosition in box2d library, and there are nothing like getX or getY, theoretically they could have been created, but since its oreianted for box2d users there was no need for that.

    But if you've been following Extending Gideros forum thread, then there we've been trying to create abstraction layer for box2d merging concept of sprite and body, where by controlling Sprite you also control body.
Sign In or Register to comment.