|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
|
|
Ajax Application Generator Generate database and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!
|
|
#1
|
|||
|
|||
|
if ($userstats3[playloc] = $attacked3[playloc] ) {
$play1hp= $userstats3[hp]; <<<------ I need these to update per round $play2hp= $attacked3[hp]; while($play1hp>0 and $play2hp>0){ <<<<<----- Or this will allways be true if it was on startup $play1newhp= $userstats3[hp]; $play2newhp= $attacked3[hp]; $player1dmg = $userstats3['str']/2; $player2dmg = $attacked3['str']/2; $play1rand = rand(0,$player1dmg); $play2rand =rand(0,$player2dmg); $newply1hp = $play1newhp - $play2rand; $newply2hp = $play2newhp - $play1rand; $updatehp ="update players set hp='$newply1hp' where playername='$userstats[playername]'";<<<<< It doesn't update quite right it lowers the value of hp but not as much as what the variable out put says it should. $updatehp2 = mysql_query($updatehp) or die( "Could not change password1"); $update2hp ="update players set hp='$newply2hp' where playername='$attacked[playername]'"; $update2hp2 = mysql_query($update2hp) or die( "Could not change password2"); echo Print "You hit $attacked3[1] for $play1rand hitpoints<br>"; echo Print "You were hit for $play2rand hitpoints by $attacked3[2]<br>";<<<< same problem echo print "you now have $newply1hp.<br>";} } So i need to know how to run this loop to look for a new hp per time the loop exicutes. Also I can't determine why the update lines aren't working right. The echo lines don't print out flawless either theres something extra being dumped in there. this is some of the file's output, You hit Leadorn for 5 hitpoints 1You were hit for 5 hitpoints by Katie 1you now have 14. 1You hit Leadorn for 4 hitpoints 1You were hit for 7 hitpoints by Katie 1you now have 12. 1You hit Leadorn for 1 hitpoints 1You were hit for 6 hitpoints by Katie 1you now have 13. 1You hit Leadorn for 5 hitpoints 1You were hit for 6 hitpoints by Katie 1you now have 13. 1You hit Leadorn for 2 hitpoints 1You were hit for 5 hitpoints by Katie 1you now have 14. 1You hit Leadorn for 4 hitpoints 1You were hit for 7 hitpoints by Katie 1you now have 12. 1You hit Leadorn for 2 hitpoints 1You were hit for 7 hitpoints by Katie 1you now have 12. 1You hit Leadorn for 3 hitpoints 1You were hit for 7 hitpoints by Katie 1you now have 12. 1You hit Leadorn for 4 hitpoints 1You were hit for 5 hitpoints by Katie 1you now have 14. 1You hit Leadorn for 4 hitpoints 1You were hit for 3 hitpoints by Katie 1you now have 16. The one's shouldn't be there and obiously the loop never ends even if they go below zero, which they don't cause something is fubar with my update. If anyone can help sort out any of these problems let me know, cause I'm stuck. |
|
#2
|
|||
|
|||
|
I'm curious, this is php you're writing?
If so does php support "$play1hp>0 and $play2hp>0" specifically the 'and' keyword since I thought you had to use '&&'. I'm presuming it does since otherwise you'd be getting a parse error and not output but thought I would ask. -KM- PS: If you could post a bit more of an explanation of what exactly is going on here it might make it easier to find out what the problem is. |
|
#3
|
|||
|
|||
|
The max script execution time isnt set to 0, and your script timeout. Try using it on a host that has script max execution time set to 0 and add the sleep function before the end of your loop.
I dunno how you're going to stop the script though For your sql queries, try doing this: $updatehp ="update players set hp=$newply1hp where playername='".$userstats[playername]."'"; |
![]() |
| Viewing: Dev Articles Community Forums > Programming > PHP Development > Loop concept and failure |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|