#2 How would I create a class so that when i skip from function to function, or even bracket to bracket, the same integers AND values would stay with the flow of the game. For example. If I would have int knife = 1; and i skipped functions how would i make knife still = 1? Also, along this same line, how would i "save" per say an item so that when i skip brackets or functions the person would still have a knife. I do realise this is not a simple 1 line code also. But help would be very helpful.
You could make it global, like this:
Code:
class ITEM
{
public:
int Strength;
int Defense;
//Constructor
ITEM(int Str, int Def)
{
Strength = Str;
Defense = Def;
}
};
ITEM Knife(4, 0);
ITEM Dagger(12, 0);
ITEM Helmet(0, 5);
void DoWhatever()
{
InflictDamage(Knife.Strength);
ShieldAttack(Helmet.Defense);
}
int main()
{
while(GameIsRunning)
{
DoWhatever();
}
return 0;
}
#3 How would I save items to a file that can be called when the .exe is run once again.
There is a tutorial on file saving on this site.