Accessing the sprite sheet

Hi Bob,

I still see that the main issue is scope problems. Perhaps these resources will help explain it in more detail:

http://lua-users.org/wiki/ScopeTutorial

http://omnigeek.robmiracle.com/2011/10/14/understanding-scope-for-beginning-programmers/

I know this topic may seem complicated, but it’s essential that you understand it 100%, because it is so fundamental to programming.

Take care,

Brent

In specific to the code block above, look at this line…

[lua]

cow:addEventListener (“collision”,CowCollision)

[/lua]

Now ask yourself, what is “cow”? Have you declared that object in the proper scope above that line? The answer is “no”, because you have not created any object named “cow” until lower down in the “cowSpawn()” function. So, Lua does not know what you’re referring to, and thus no collisions.

Brent

Hi Brent,

It worked,thanks for the tutorials,and patience :slight_smile:

Bob