PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
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  
Old June 30th, 2004, 05:50 PM
Malace Malace is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Posts: 3 Malace User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Angry Loop concept and failure

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.


Reply With Quote
  #2  
Old July 1st, 2004, 06:37 AM
kode_monkey kode_monkey is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 367 kode_monkey User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 m 21 sec
Reputation Power: 5
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.

Reply With Quote
  #3  
Old July 1st, 2004, 06:49 PM
velocityX velocityX is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Posts: 72 velocityX User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 11 m 36 sec
Reputation Power: 6
Send a message via AIM to velocityX
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]."'";

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingPHP Development > Loop concept and failure


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway