PDA

View Full Version : limit a while loop ?


acer240
06-13-2011, 12:39 PM
hello all, new to here so will jump straight in with an issue i need help with :-D

Basically i have an online game and need to limit the output displayed from a loops process....

so to make that clearer....

it is for an attack script the loop cycles through until one of the users Health reaches 0 to end the battle but , should they be closely matched and it creates a one hit each battle.....the output can be upto 1000 lines long saying xx hit for 1, xxx hit back for 1....

i need to make it display only a few lines then say something simple like 'log truncated' ...but ensure the actually loop still finishes its cycle until someone reaches 0 health to 'die' if that makes sense


this is the loop that handles it all

$wait = ($User->moddedspeed > $attack_person->moddedspeed) ? 1 : 0;
while($yourhp > 0 && $theirhp > 0){
$damage = $attack_person->moddedstrength - $User->moddeddefense;
$damage = ($damage < 1) ? 1 : $damage;
if($wait == 0){
$yourhp = $yourhp - $damage;
echo "<center><font size=2> " . $attack_person->formattedname . "<font size=2> hit you for <font color=orange>" . prettynum($damage) . "</font> damage using their <font color=orange>".$attack_person->weaponname.". </font><br>";
} else {
$wait = 0;
}
if($yourhp > 0) {
$damage = $User->moddedstrength - $attack_person->moddeddefense;
$damage = ($damage < 1) ? 1 : $damage;
$theirhp = $theirhp - $damage;
echo "<center><font size=2>You hit <b>" . $attack_person->formattedname . "</b> for <font color=orange>" . prettynum($damage) . " </font> damage using your <font color=orange>".$User->weaponname.". </font></center><br>";
}
ANY help would be hugely appreciated

thanks all :-D