Shocker88 Posted October 30, 2007 Share Posted October 30, 2007 Hey, just having some trouble with the variables $agility and $eagility losing their set initial values (in this case 5 and 8 respectively) when in the following code: $agility = $ag1; $eagility = $ag2; while ($hitpoints >= 1 and $ehitpoints >= 1) { if ($agility >= $eagility) { $ehitpoints = $ehitpoints - $strength; echo $ehitpoints . " you <br>"; $eagility = $eagility + $ag2; } else { $hitpoints = $hitpoints - $estrength; echo $hitpoints . " enemy <br>"; $agility = $agility + $ag1; } } the $ag1 and $ag2 variables seem to have the same problem, however $hitpoints, $ehitpoints and $estrength seem to be holding the correct values...Any help on this matter would be much appreciated! Thanks in advance. EDIT: To clarify this the values seem to be set to either 0 or null when called, both before and after the line that should edit the value (ie. $agility = $agility + $ag1;). Quote Link to comment https://forums.phpfreaks.com/topic/75360-variable-losing-set-value-in-loopnested-if/ Share on other sites More sharing options...
only one Posted October 30, 2007 Share Posted October 30, 2007 while ($hitpoints >= 1 and $ehitpoints >= 1) Change too: while ($hitpoints >= 1 && $ehitpoints >= 1) For the i don't see much point in adding the $eagility with the variable that it is set to. It is impossible for your variables to be losing their values. ---------- Try echoing the $ag1, $ag2 variables. Are they even set further up the code? Quote Link to comment https://forums.phpfreaks.com/topic/75360-variable-losing-set-value-in-loopnested-if/#findComment-381150 Share on other sites More sharing options...
Shocker88 Posted October 30, 2007 Author Share Posted October 30, 2007 Gosh..needed double ='s to assign the same value...transfering knowlegde from other languages can be a killer on syntax. Thanks for the reply - made me look at it differently and revealed the error heh. Quote Link to comment https://forums.phpfreaks.com/topic/75360-variable-losing-set-value-in-loopnested-if/#findComment-381159 Share on other sites More sharing options...
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.