I am making a windows application in Visual Studio and it has a little twist on it so its like a game (without graphics).
But I just encountered a problem, in a game you often have health, but my problem is that I want to keep the variables "alive" (meaning to keep them from getting destroyed by scope) and use them as health for example.
But the variables will go out of scope because of the way their value is going to change, for example if I have like a attack button I need to first create a attack variable to determine how much damage i'm going to do, then i need to make a health variable for the mos´nster i'm going to hit.
So when the button that is going to trigger this is going to first create 1 attack and 1 health variable, then take the attack variable minus the health variable, then my variables will get destroyed by scope and when i press the button again the variables I had before will be gone.
(some code that might make it clearer for the person who is going to answer):
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
int Attack = 10;
int Health = 100;
Health = Health - Attack;
this->label1->Text = L"You did 10 Damage";
}
And how do I Display a variables value in a label, something loke this:
this->label1->Text = L"You did <attack> Damage";
Thank You! :)