"You can use a global variable for each level that has a stars total." You just make a global variable for each level, level1_starcount, level2_starcount. Assuming you know the amount of stars and in what level and they are not procedurally generated or something. You just set level 1 to 5, level 2 to 5, total is 100 etc. Then when you collect a star in level1 you subtract 1 from level1_starcount and the total.