I can't get this :\

Hi,
It seems like I didn’t really got how and in what order I should put function and other declarations.
When I try a function like this

local function SayHI()
if Object.alpha == 1 then
print (“ciao”)
end
end

called when a “tap” event takes place.

if I put it before creating an object=display.newImage
it gives me an error : attempt to index upvalue ‘Object’ (nil Value)

if I put it at the end of file, after I declared both the object and the listener, it just doesn’t fire.

If I put it between the declared listeren AND the declaration to create the new object, everything works.

I’m doing something wrong, or in Lua the order is really important? It makes thing more complicated for me this way :\ [import]uid: 8486 topic_id: 1913 reply_id: 301913[/import]

In Lua the order you declare things is VERY important and also if you declare them as LOCAL or GOBAL. I suggest that you study Lua a little, there are some good resources in the net. [import]uid: 5712 topic_id: 1913 reply_id: 5641[/import]

Yes, as Mike stated order in Lua is very important. Sometimes you can’t place everything in the proper places so you can create a “forward reference.” This is simply defining an object or variable early in your program that is assigned later. In your example you can add this to the beginning of your code file:

local Object -- forward reference  

Later in your program you can assign Object (without the “local” tag).

I generally group all the forward references together in a block.

-Tom [import]uid: 7559 topic_id: 1913 reply_id: 5697[/import]

Yes, thanks, that was what I did, thing is, when I called them back again, I used the “local” again, probably creating new ones :smiley:
Thanks for clarifying this, it was really helpful.

Now, I was working with groups, and I noticed that the x and y coordinates of the object of a group aren’t related to the x and y of the stage, but of the group.
So, if I move a group, the coordinates of the objects in it are always the same.
That’s not much of a problem, but I was thinking if it was possible to let them be related to the stage while moving their group. [import]uid: 8486 topic_id: 1913 reply_id: 5698[/import]

Yes, objects that are part of a group have their x and y coordinates relative to their parent (group). You can use the object.stageBounds property to return the values in screen coordinates.

-Tom [import]uid: 7559 topic_id: 1913 reply_id: 5700[/import]