function collectStar(event)
if event.phase == “began” then
if (event.object1.name == “star” and event.object2.name == “myPlayer”) then
display.remove(event.object1)
starsCollected = starsCollected + 1
print(“Player collected a star!”)
end
end
end
I noticed in the console that it’s printing “Player has collected a star” multiple (3X) times when the player grabs them. It’s also feeding the starsCollected an incorrect value. How do I prevent this from happening?
More importantly…I have a feeling that I’m not coding my game correctly for what I REALLY want it to do. I’d like to have a level select screen (which I already have the template for) and the “stars” on each level to be saved/stored so that it will show on top of the level button on the level select screen. Is there a better way to log the star counter? Maybe a tutorial somewhere on the web that explains how to structure your game? I read a couple threads and sites that talk about using tables (which I kind of understand them, but not how to use them in my case). I’ve just been going with what I know/learned thus far but like I said…I feel like I’m not doing it the right way (even though the game looks and plays nicely).
My apologies if I come off as a newb who posts too much lol. I’ve been a tech geek since I was 12, and always wanted to learn how to code (especially games). This is my passion. When I found Corona, I thought it was the perfect place to start…and so far I was right.