Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS

Lives

I have added 30 lives into my game. But when the game ends, the lives go back to 30. I want the lives to stay at the number of lives the player has left, and not regenerate back to 30. And then for the lives to regenerate one by one every 5 minutes. Does anyone know how i could do this?

1 Answer

If your working off of the Space Cat game, then you will need to adjust code in the Game Over Method to not reset the lives.

Then you would have to build in a way to track the system time. Once you have that you would need to check the time while the game is running to see if 5 minutes has past or not. Any time lives are added or removed you have to update your file with the number of lives the player has.

When the game is restarted you will have to compare how long the player was a away and for every 5 minutes give back lives. This can be done on start up in the viewController.