grlayouts Posted February 12, 2007 Share Posted February 12, 2007 if i have an attack script $mypower = ($mywep[power] + $stat[strength] - ($earm[power] / 2)); \\player $epower = ($enemy[strength] + $ewep[power] - $myarm[power]); \\enemy if player power = 20 & enemy power = -10 how do i make it so it cant go into negative? Quote Link to comment Share on other sites More sharing options...
ToonMariner Posted February 12, 2007 Share Posted February 12, 2007 yo need an if statement in there right after you hav done the calcs on power. Check if either are <= 0 if they are then stop the contest if not carry on. Quote Link to comment Share on other sites More sharing options...
grlayouts Posted February 12, 2007 Author Share Posted February 12, 2007 tried that and couldnt get it working? Quote Link to comment Share on other sites More sharing options...
grlayouts Posted February 12, 2007 Author Share Posted February 12, 2007 no tried again still cant get it working. Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 12, 2007 Share Posted February 12, 2007 You wanna post a little more code and why it's not working. Quote Link to comment Share on other sites More sharing options...
grlayouts Posted February 12, 2007 Author Share Posted February 12, 2007 thats it.. the above code is the problem. i just need to know if one of them queries = -something how i can default it to '0' Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted February 12, 2007 Share Posted February 12, 2007 Try this: <?php $user_power = -10; if($user_power > -10){ # do some damage }else{ # don't do damage } ?> Quote Link to comment Share on other sites More sharing options...
grlayouts Posted February 12, 2007 Author Share Posted February 12, 2007 so $mypower = 0 where $mypower <0 should work? Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 12, 2007 Share Posted February 12, 2007 sure. Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted February 12, 2007 Share Posted February 12, 2007 are you sure that will work? I didn't think that would work. <?php $mypower = 0; if($mypower<0){ #can't attack }else{ #allow attack } ?> Quote Link to comment Share on other sites More sharing options...
grlayouts Posted February 12, 2007 Author Share Posted February 12, 2007 your right it didnt.. i think she just agree's to anything.. lol! Quote Link to comment Share on other sites More sharing options...
grlayouts Posted February 12, 2007 Author Share Posted February 12, 2007 $mypower = ($mywep[power] + $stat[strength] - $earm[power]); if($mypower<0){ ($mypower=0); $epower = ($enemy[strength] + $ewep[power] - $myarm[power] ); if($epower<0){ ($epower=0); this still aint working, when i run the script i get Fatal error: Unknown function: attackback() in /home/hobotown/public_html/battle.php on line 566 Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 12, 2007 Share Posted February 12, 2007 You're still not posting the relevant code, that's why I agreed. You posted SQL statements, and what you wrote will work in SQL. Your code has nothing about the function (attackback()) that the error is referencing. You said you tried the suggestion Toon posted, yet when I asked you to post it you said you had, but the code doesn't have his suggestion. This code is missing brackets: $mypower = ($mywep[power] + $stat[strength] - $earm[power]); if($mypower<0){ $mypower=0; } $epower = ($enemy[strength] + $ewep[power] - $myarm[power] ); if($epower<0){ $epower=0; } Quote Link to comment Share on other sites More sharing options...
grlayouts Posted February 12, 2007 Author Share Posted February 12, 2007 because the other code i know works. Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 12, 2007 Share Posted February 12, 2007 How are you so sure? You can't figure out how to do an if statement, but you're sure the rest of the code works? I'm not saying post all the code, but the ERROR is very specific about the function and the line, and what you posted has nothing to do with it. What you posted was incorrect code however, and if you fix the brackets that may fix it. Quote Link to comment Share on other sites More sharing options...
grlayouts Posted February 12, 2007 Author Share Posted February 12, 2007 because i wanted to avoid if statements if possible, my battle script is 800 lines, reffering back to functions ie function attack() { with globals global $stat; global $enemy; global $myarm; global $mywep; global $earm; global $ewep; i know it worked. Quote Link to comment 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.