Hi all.
Again, I am struggling so I seek the advice from you all.
In each level of my game, there are items to collect. They are not important in themselves but extra bonuses for each level.
Between levels I’d like a menu that showed which levels were completed, and how many of the bonuses you collected. If you have played cut the rope, you’ll understand. You ahve finished but only collected 2 of the three stars.
How would you store this info when there are a HEAp of levels? I can find globalDict tuts that carry a score from one level to the next but I struggle to understand how to write each level’s progress to a file then read that data and display it. ;(
You will need some kind of data structure to store this information. This could be something simple like a list (where the list index is the level) or a dictionary keyed by a level name.
I personally would recommend using a dictionary so you don’t run into problems reordering levels.
To get the dictionary going would look something like this:
# Initialize a new dictionary
items_collected = {}
# Set up a counter for that level's name
items_collected[level.name] = 0
# When the player gets one of those items, you can increment the count for that level
items_colllected[level.name] += 1
Most likely those three lines wouldn’t be next to each other, but they each show how to make use of the dictionary. In this case I am assuming a level object that has details (including name) about the level. If you wanted to store more information about the state of each level, you could just throw the level object itself into the dictionary.
There are several ways you can go about this, and I hope I at least gave you some ideas.
Thanks to both of you. I have it working perfectly (after a night of tearing my hear out at my own stupidity… you know, when you’re chasing something that’s wrong and you find out it’s because you did something silly).