MadTechie Posted August 13, 2007 Share Posted August 13, 2007 you sure your looking at the correct userĀ ? (i have to ask) Quote Link to comment https://forums.phpfreaks.com/topic/64649-solved-weird-while-problem/page/2/#findComment-322377 Share on other sites More sharing options...
uwannadonkey Posted August 13, 2007 Author Share Posted August 13, 2007 yes, id 9 catncobra Ā im attacking id 9 Ā its hp is 100. Ā how about we echo enemy's HP every so often and see when it turns 0? Quote Link to comment https://forums.phpfreaks.com/topic/64649-solved-weird-while-problem/page/2/#findComment-322381 Share on other sites More sharing options...
MadTechie Posted August 13, 2007 Share Posted August 13, 2007 how about we uncomment that code Ā #$usersql = @mysql_query("SELECT * FROM users WHERE ID = '$uID'"); #$user = @mysql_fetch_object($usersql); Quote Link to comment https://forums.phpfreaks.com/topic/64649-solved-weird-while-problem/page/2/#findComment-322385 Share on other sites More sharing options...
uwannadonkey Posted August 13, 2007 Author Share Posted August 13, 2007 GOD VS. CatNCobra Welcome to the Battle Arena.User HP:190 Enemy HP:0 Ā still, commented out, it still doesnt show the proper HP. Ā i just turned enemy HP into 0, and it didnt echo the "your enemy is already dead" line Ā instead it says Ā GOD VS. CatNCobra Welcome to the Battle Arena.User HP:190 Enemy HP:0 Ā Quote Link to comment https://forums.phpfreaks.com/topic/64649-solved-weird-while-problem/page/2/#findComment-322388 Share on other sites More sharing options...
MadTechie Posted August 13, 2007 Share Posted August 13, 2007 OK lets check for errors in the SQL Part Ā #commented out if called from header! $usersql = @mysql_query("SELECT * FROM users WHERE ID = '$uID'"); $user = @mysql_fetch_object($usersql) or die(mysql_error()); $enemysql = @mysql_query("SELECT * FROM users WHERE ID = '$eID'"); $enemy = @mysql_fetch_object($enemysql) or die(mysql_error()); print_r($enemy); Quote Link to comment https://forums.phpfreaks.com/topic/64649-solved-weird-while-problem/page/2/#findComment-322391 Share on other sites More sharing options...
uwannadonkey Posted August 13, 2007 Author Share Posted August 13, 2007 ok Ā THIS showed up(yay!) Ā stdClass Object ( [iD] => 9 [username] => CatNCobra [display_name] => CatNCobra [password] => ecb69279ec2c85c2a63ad2f43b8bbeb5 => catncobra@gmail.com [activation_code] => 6a1dc38c5621a76daf3e3acf76b1baa0 [permission_level] => 0 [donator_days] => 0 [level] => 51 [exp] => 0 [exp_required] => 75 [energy] => 7 [max_energy] => 150 [hp] => 100 [max_hp] => 100 [attack] => 1895 [defense] => 5 [agility] => 5 [diamond] => 5 [gold] => 0 [avatar] => [sig] => [energy_used] => 0 [iP] => [battle_won] => 0 [battle_lost] => 0 [total_battles] => 0 [storage] => 0 [bank_gold] => 4417 [crystal] => 8 [element] => 0 [rank] => 0 [forest] => 0 [gold2] => [weapon] => 0 ) GOD VS. CatNCobra Welcome to the Battle Arena.User HP:190 Enemy HP:0 Ā u see? his hp is 100 Ā Quote Link to comment https://forums.phpfreaks.com/topic/64649-solved-weird-while-problem/page/2/#findComment-322394 Share on other sites More sharing options...
MadTechie Posted August 13, 2007 Share Posted August 13, 2007 quick update change elseif ($enemy->hp = 0) to elseif ($enemy->hp == 0) Quote Link to comment https://forums.phpfreaks.com/topic/64649-solved-weird-while-problem/page/2/#findComment-322397 Share on other sites More sharing options...
uwannadonkey Posted August 13, 2007 Author Share Posted August 13, 2007 changed it, now the thing is, my page isnt loading up. Ā i mean, it says loading, but nothing is really happening Ā WOAH, hold on! Ā in mysql, me and cat's hp has been updated:Ā look at it! Ā 18446744073659623138-> my hp 18446744073357442826Ā ->his hp Ā thats the HP that we both have! Quote Link to comment https://forums.phpfreaks.com/topic/64649-solved-weird-while-problem/page/2/#findComment-322402 Share on other sites More sharing options...
MadTechie Posted August 13, 2007 Share Posted August 13, 2007 OK change while ($user->hp > 0 && $enemy->hp > 0) to while ($user->hp > 0 || $enemy->hp > 0) Ā Ā Quote Link to comment https://forums.phpfreaks.com/topic/64649-solved-weird-while-problem/page/2/#findComment-322403 Share on other sites More sharing options...
MadTechie Posted August 13, 2007 Share Posted August 13, 2007 full updated code Ā <?php include('inc/header.php'); $eID = $enemy->ID; $uID = (int)$_GET['ID']; if ($uID > 0) { #if called from header! $enemysql = @mysql_query("SELECT * FROM users WHERE ID = '$eID'"); $enemy = @mysql_fetch_object($enemysql); $usersql = @mysql_query("SELECT * FROM users WHERE ID = '$uID'"); $user = @mysql_fetch_object($usersql); echo "$user->display_name"; echo ' VS. ';echo "$enemy->display_name<br>"; }else{ die("error"); } if ($enemy->ID == $user->ID) { echo' You cant attack yourself!'; } elseif ($user->hp <= 0) { echo ' You are in NO condition to do battle'; } elseif ($enemy->hp == 0) { echo ' Your Enemy Is Already Dead!'; } elseif ($user->energy <= 4) { echo ' Not enough energy!'; } elseif ($user->attack < $enemy->defense) { echo ' You look at your opponent, and wet your pants at his/her strength.Ā You lose the battle.<br><br><br><br><br><br><br><br><br>'; mysql_query("UPDATE `users` SET hp = 0 WHERE ID = '$user->ID'"); } elseif ($user->defense > $enemy->attack) { echo' Your opponent takes one look at you, and dies in fear<br><br><br><br><br><br><br><br><br>'; mysql_query("UPDATE `users` SET hp = 0 WHERE ID = '$enemy->ID'"); } else { echo' Welcome to the Battle Arena.'; if ( $user->agility > $enemy->agility) { $firstattack = '1'; }else{ $firstattack = '2'; } echo "UserĀ HP:".$user->hp; echo "<br>Enemy HP:".$enemy->hp; while ($user->hp > 0 || $enemy->hp > 0) { echo "attack<br>"; //add flush(); //add if ($firstattack == 1) { $dmg = ($user->attack) - ($enemy->defense); mysql_query("UPDATE `users` SET hp = hp-($dmg) WHERE ID = $enemy->ID"); echo "$user->display_name"; echo' has done '; echo "$dmg"; echo ' damage against '; echo "$enemy->display_name"; } if ($firstattack == 2) { $dmg = ($enemy->attack) - ($user->defense); mysql_query("UPDATE `users` SET hp = hp-($dmg) WHERE ID = $user->ID"); echo "$enemy->display_name"; echo' has done '; echo "$dmg"; echo ' damage against '; echo "$user->display_name"; } if ($firstattack != 1) { $dmg = ($user->attack) - ($enemy->defense); mysql_query("UPDATE `users` SET hp = hp-($dmg) WHERE ID = $enemy->ID"); echo "$user->display_name"; echo' has done '; echo "$dmg"; echo ' damage against '; echo "$enemy->display_name"; } if ($firstattack != 2) { $dmg = ($enemy->attack) - ($user->defense); mysql_query("UPDATE `users` SET hp = hp-($dmg) WHERE ID = $user->ID"); echo "$enemy->display_name"; echo' has done '; echo "$dmg"; echo ' damage against '; echo "$user->display_name"; } //get new values $enemysql = @mysql_query("SELECT * FROM users WHERE ID = '$uID'"); $enemy = @mysql_fetch_object($enemysql); $usersql = @mysql_query("SELECT * FROM users WHERE ID = '$eID'"); $user = @mysql_fetch_object($usersql); } } include('inc/footer.php'); ?> Quote Link to comment https://forums.phpfreaks.com/topic/64649-solved-weird-while-problem/page/2/#findComment-322405 Share on other sites More sharing options...
uwannadonkey Posted August 13, 2007 Author Share Posted August 13, 2007 hold on, b4 i updated the while code that u told me to, the page loaded, with like 1 million attack lines, constantly me attacking him, and back and forth Quote Link to comment https://forums.phpfreaks.com/topic/64649-solved-weird-while-problem/page/2/#findComment-322407 Share on other sites More sharing options...
MadTechie Posted August 13, 2007 Share Posted August 13, 2007 yep, attach until both were dead,, code has be updated to attack until one dies (their a few updates use the full code above) Quote Link to comment https://forums.phpfreaks.com/topic/64649-solved-weird-while-problem/page/2/#findComment-322410 Share on other sites More sharing options...
uwannadonkey Posted August 13, 2007 Author Share Posted August 13, 2007 the thing is, we both had like 100 hp each, and it changed our hp to 18billion or whatever, and we were both doing like 286 dmg(me) and he was doing 1890 dmg. Quote Link to comment https://forums.phpfreaks.com/topic/64649-solved-weird-while-problem/page/2/#findComment-322412 Share on other sites More sharing options...
uwannadonkey Posted August 13, 2007 Author Share Posted August 13, 2007 how do u change it so it knows when only 1 dies, not both? *EDIT* i put in ur new code, and mroe errors: Ā CatNCobra VS. Your Enemy Is Already Dead! Ā he isnt dead, and why is HE attacking noone? its supposed to be GOD vs catncobra Quote Link to comment https://forums.phpfreaks.com/topic/64649-solved-weird-while-problem/page/2/#findComment-322413 Share on other sites More sharing options...
uwannadonkey Posted August 13, 2007 Author Share Posted August 13, 2007 how do u change it so it knows when only 1 dies, not both? *EDIT* i put in ur new code, and mroe errors: Ā CatNCobra VS. Your Enemy Is Already Dead! Ā he isnt dead, and why is HE attacking noone? its supposed to be GOD vs catncobra Ā fixed that part Ā *edit#2* Ā i plugged in ur code, the code isnt properly working, its changing bioth our HP toĀ 18446744073650332346 Quote Link to comment https://forums.phpfreaks.com/topic/64649-solved-weird-while-problem/page/2/#findComment-322418 Share on other sites More sharing options...
MadTechie Posted August 13, 2007 Share Posted August 13, 2007 i assume you set the HP's back to a "normal" value please note that the $dmg is set to the HP left and not the amount taken (just want to check its running ok) Ā while update echo "User Start HP:".$user->hp; echo "<br>Enemy Start HP:".$enemy->hp; while ($user->hp > 0 || $enemy->hp > 0) { echo "attack<br>"; //add echo "UserĀ HP:".$user->hp; echo "<br>Enemy HP:".$enemy->hp; flush(); //add if ($firstattack == 1) { $dmg = $enemy->hp - ($user->attack - $enemy->defense); mysql_query("UPDATE `users` SET hp = hp-($dmg) WHERE ID = $enemy->ID"); echo "$user->display_name"; echo' has done '; echo "$dmg"; echo ' damage against '; echo "$enemy->display_name"; } if ($firstattack == 2) { $dmg = $user->hp - ($enemy->attack - $user->defense); mysql_query("UPDATE `users` SET hp =($dmg) WHERE ID = $user->ID"); echo "$enemy->display_name"; echo' has done '; echo "$dmg"; echo ' damage against '; echo "$user->display_name"; } if ($firstattack != 1) { $dmg = $enemy->hp - ($user->attack) - ($enemy->defense); mysql_query("UPDATE `users` SET hp = ($dmg) WHERE ID = $enemy->ID"); echo "$user->display_name"; echo' has done '; echo "$dmg"; echo ' damage against '; echo "$enemy->display_name"; } if ($firstattack != 2) { $dmg = $user->hp - ($enemy->attack) - ($user->defense); mysql_query("UPDATE `users` SET hp = ($dmg) WHERE ID = $user->ID"); echo "$enemy->display_name"; echo' has done '; echo "$dmg"; echo ' damage against '; echo "$user->display_name"; } //get new values $enemysql = @mysql_query("SELECT * FROM users WHERE ID = '$uID'"); $enemy = @mysql_fetch_object($enemysql); $usersql = @mysql_query("SELECT * FROM users WHERE ID = '$eID'"); $user = @mysql_fetch_object($usersql); } Quote Link to comment https://forums.phpfreaks.com/topic/64649-solved-weird-while-problem/page/2/#findComment-322423 Share on other sites More sharing options...
uwannadonkey Posted August 13, 2007 Author Share Posted August 13, 2007 the page is taking forever to load, and the HUGE HP number keeps reappearing Ā *how do i make a battle system where theres 1 winner?Ā thats what i wanted to make, anyway, cuz like, i thought if one part of the while is false, its all false, was i wrong? Ā this showed up, its huge, so i put a code bracket around it: GOD VS. CatNCobra Welcome to the Battle Arena.User Start HP:100 Enemy Start HP:100attack User HP:100 Enemy HP:100CatNCobra has done -1790 damage against GODGOD has done -178 damage against CatNCobraattack User HP:18446744073709551438 Enemy HP:18446744073709549826GOD has done 1.84467440737E+19 damage against CatNCobraCatNCobra has done 1.84467440737E+19 damage against GODattack User HP:18446744073699999744 Enemy HP:18446744073699999744GOD has done 1.84467440737E+19 damage against CatNCobraCatNCobra has done 1.84467440737E+19 damage against GODattack User HP:18446744073699999744 Enemy HP:18446744073699999744GOD has done 1.84467440737E+19 damage against CatNCobraCatNCobra has done 1.84467440737E+19 damage against GODattack User HP:18446744073699999744 Enemy HP:18446744073699999744GOD has done 1.84467440737E+19 damage against CatNCobraCatNCobra has done 1.84467440737E+19 damage against GODattack User HP:18446744073699999744 Enemy HP:18446744073699999744GOD has done 1.84467440737E+19 damage against CatNCobraCatNCobra has done 1.84467440737E+19 damage against GODattack User HP:18446744073699999744 Enemy HP:18446744073699999744GOD has done 1.84467440737E+19 damage against CatNCobraCatNCobra has done 1.84467440737E+19 damage against GODattack User HP:18446744073699999744 Enemy HP:18446744073699999744GOD has done 1.84467440737E+19 damage against CatNCobraCatNCobra has done 1.84467440737E+19 damage against GODattack User HP:18446744073699999744 Enemy HP:18446744073699999744GOD has done 1.84467440737E+19 damage against CatNCobraCatNCobra has done 1.84467440737E+19 damage against GODattack User HP:18446744073699999744 Enemy HP:18446744073699999744GOD has done 1.84467440737E+19 damage against CatNCobraCatNCobra has done 1.84467440737E+19 damage against GODattack User HP:18446744073699999744 Enemy HP:18446744073699999744GOD has done 1.84467440737E+19 damage against CatNCobraCatNCobra has done 1.84467440737E+19 damage against GODattack User HP:18446744073699999744 Enemy HP:18446744073699999744GOD has done 1.84467440737E+19 damage against CatNCobraCatNCobra has done 1.84467440737E+19 damage against GODattack User HP:18446744073699999744 Enemy HP:18446744073699999744GOD has done 1.84467440737E+19 damage against CatNCobraCatNCobra has done 1.84467440737E+19 damage against GODattack User HP:18446744073699999744 Enemy HP:18446744073699999744GOD has done 1.84467440737E+19 damage against CatNCobraCatNCobra has done 1.84467440737E+19 damage against GODattack User HP:18446744073699999744 Quote Link to comment https://forums.phpfreaks.com/topic/64649-solved-weird-while-problem/page/2/#findComment-322429 Share on other sites More sharing options...
uwannadonkey Posted August 13, 2007 Author Share Posted August 13, 2007 ahhhh, sigh anyone help? Quote Link to comment https://forums.phpfreaks.com/topic/64649-solved-weird-while-problem/page/2/#findComment-322448 Share on other sites More sharing options...
MadTechie Posted August 13, 2007 Share Posted August 13, 2007 ok i have re-written the while section Ā echo "User Start HP:".$user->hp; echo "<br>Enemy Start HP:".$enemy->hp; $attacker = ($user->agility > $enemy->agility); while ($user->hp > 0 && $enemy->hp > 0) { echo "attack<br>"; //add echo "UserĀ HP:".$user->hp; echo "<br>Enemy HP:".$enemy->hp; flush(); //add if($attacker) { $dmg = (int)($user->attack - $enemy->defense); $HPLeft = (int)($enemy->hp - dmg); mysql_query("UPDATE `users` SET hp = ($HPLeft) WHERE ID = $enemy->ID"); echo "$user->display_nameĀ has done $dmg damage against $enemy->display_name"; }else{ $dmg = (int)($enemy->attack - $user->defense); $HPLeft = (int)($user->hp - dmg); mysql_query("UPDATE `users` SET hp =($HPLeft) WHERE ID = $user->ID"); echo "$enemy->display_name has done $dmg damage against $user->display_name"; $attacker = !$attacker; //get new values $enemysql = @mysql_query("SELECT * FROM users WHERE ID = '$uID'"); $enemy = @mysql_fetch_object($enemysql); $usersql = @mysql_query("SELECT * FROM users WHERE ID = '$eID'"); $user = @mysql_fetch_object($usersql); } } Quote Link to comment https://forums.phpfreaks.com/topic/64649-solved-weird-while-problem/page/2/#findComment-322449 Share on other sites More sharing options...
uwannadonkey Posted August 13, 2007 Author Share Posted August 13, 2007 Internal Server Error The server encountered an internal error or misconfiguration and was unable to complete your request. Ā Please contact the server administrator, webmaster@donkeygame.1gig.biz and inform them of the time the error occurred, and anything you might have done that may have caused the error. Ā More information about this error may be available in the server error log. Ā Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request. Ā Ā wth does that mean Quote Link to comment https://forums.phpfreaks.com/topic/64649-solved-weird-while-problem/page/2/#findComment-322453 Share on other sites More sharing options...
MadTechie Posted August 13, 2007 Share Posted August 13, 2007 404 Not Found, Ā wait a minute and upload the file again.. check the FTP logs it may of failed (had that before) Quote Link to comment https://forums.phpfreaks.com/topic/64649-solved-weird-while-problem/page/2/#findComment-322456 Share on other sites More sharing options...
uwannadonkey Posted August 13, 2007 Author Share Posted August 13, 2007 no, it was a 500 internal server error, not a 404 Ā isnt that the while function working indefinetly? Quote Link to comment https://forums.phpfreaks.com/topic/64649-solved-weird-while-problem/page/2/#findComment-322459 Share on other sites More sharing options...
uwannadonkey Posted August 13, 2007 Author Share Posted August 13, 2007 i was right: Ā 13-Aug-2007 09:08:42] PHP Fatal error:Ā Maximum execution time of 30 seconds exceeded in /home/donkey9/public_html/attack.php on line 71 Ā Ā thats in my error log Quote Link to comment https://forums.phpfreaks.com/topic/64649-solved-weird-while-problem/page/2/#findComment-322460 Share on other sites More sharing options...
MadTechie Posted August 13, 2007 Share Posted August 13, 2007 indeed forgot a } while ($user->hp > 0 && $enemy->hp > 0) { echo "attack<br>"; //add echo "UserĀ HP:".$user->hp; echo "<br>Enemy HP:".$enemy->hp; flush(); //add if($attacker) { $dmg = (int)($user->attack - $enemy->defense); $HPLeft = (int)($enemy->hp - dmg); mysql_query("UPDATE `users` SET hp = ($HPLeft) WHERE ID = $enemy->ID"); echo "$user->display_nameĀ has done $dmg damage against $enemy->display_name"; }else{ $dmg = (int)($enemy->attack - $user->defense); $HPLeft = (int)($user->hp - dmg); mysql_query("UPDATE `users` SET hp =($HPLeft) WHERE ID = $user->ID"); echo "$enemy->display_name has done $dmg damage against $user->display_name"; } //added <-**** $attacker = !$attacker; //get new values $enemysql = @mysql_query("SELECT * FROM users WHERE ID = '$uID'"); $enemy = @mysql_fetch_object($enemysql); $usersql = @mysql_query("SELECT * FROM users WHERE ID = '$eID'"); $user = @mysql_fetch_object($usersql); } Ā this is much easier when you have it on your own server and don't have your boss walking around the office Quote Link to comment https://forums.phpfreaks.com/topic/64649-solved-weird-while-problem/page/2/#findComment-322461 Share on other sites More sharing options...
uwannadonkey Posted August 13, 2007 Author Share Posted August 13, 2007 how do code it so only one winner? Quote Link to comment https://forums.phpfreaks.com/topic/64649-solved-weird-while-problem/page/2/#findComment-322466 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.