Pheonix Posted October 14, 2008 Posted October 14, 2008 I am trying to set a variable that goes down by 1 every time a link is clicked. I am unsure how to do the variable properly. $start = 10; $monsterhp = $start - $damage; $hit = rand(1,2); if ($hit = 1) { $damage = 1; echo "You hit the monster for 1 hp damage. Hit Again"; } else { $damage = 0; echo "It hit you instead. Try Again"; } Some help would be appreciated. Quote
Floydian Posted October 14, 2008 Posted October 14, 2008 Re: How do I Variable Question The value that you want decremented needs to be stored in some sort of memory. You can use a session var, or store this in a database or file. I'd opt for the session var. // is the session var set? if (!isset($_SESSION['start']) { // it's not set, so initialize it $_SESSION['start'] = 10; } else { // decrement the var by one $_SESSION['start']--; } Quote
Pheonix Posted October 15, 2008 Author Posted October 15, 2008 Re: How do I Variable Question Thank you Floydian, I will definitely try that out :-) Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.