Click here to Skip to main content
15,886,919 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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! :)
Posted
Updated 25-Oct-11 0:16am
v4
Comments
Toniyo Jackson 7-Jan-11 6:44am    
Use pre tag for code.
Nuri Ismail 7-Jan-11 12:50pm    
Changed tag from C++ to C++\CLI.
Albert Holguin 25-Oct-11 9:45am    
I still see the tag as C++
Karsten Malmquist 29-Oct-11 12:34pm    
Honestly, I don't really know what C++/CLI is. Although now that i'm thinking about it, i'm not sure why I changed it back.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900