I would use arrays, it makes things easier, and it will be global. One thing about your game, is that you are using actor variables, when actor variables aren't neccesary. You should only use actor variables if you are dealing with clones, or multiple actors will be using their own version of the variable. So, since there is only one player, you have always been needing to do player.Item1, where it would be better to if it were global.
Anyway, declare an array like this.
Global Code
- Code: Select all
int items[4];
As most things, it is indexed, 0-3, which means Item1 would be stored in items[0], Item2 in items[1], and so on. Other than declaring them, int arrays act exactly pretty similar to ints. There are a few tricks you can do with them as well. But if you want to add an item3, use this.
- Code: Select all
items[2]++;
One thing is you can make a matching array, that holds the amount of hp the items will give.
Global Code
- Code: Select all
int items[4];
int items_stats[4] = {10, 20, 30, 40};
So, when you are increasing hp, you can use this.
- Code: Select all
if(items[2]>0)
{
items[2]--;
player.hp+=item_stats[2];
}