[Resolved] Retrieving components of other game objects

Hi Guys. Just started using the engine so have a very basic question. I am following the Getting Started Tutorial and I was wondering instead of hard coding the position of the blocks as such:
if pos.x <= -228 then 5
pos.x = 1368 + (pos.x + 228)
end
I would like to do that by retrieving the width of the sprite and use that at runtime instead of using the hardcoded value of “228”. Same with the value “1368” - I would rather keep track of the last object and use its position to position the new block. In the current tutorial, I have the controller game object which has the script attached to it and I cant find a way to retrieve the game object by the name “ground0”. I want to retrive the game object so that I can then access the size property of the sprite component attached to it.

Hi and welcome!

Check out http://www.defold.com/ref/sprite#size

Note that the example uses shorthand notation to address the component in the current game object “#component”. You can specify an object with “gameobject#component”. For instance “ground0#sprite1”.

Cheers,

Mikael

Thanks! That worked the way I wanted it too!