Jump to content

Variable losing set value in loop/nested if()


Shocker88

Recommended Posts

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;).

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?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.