Jump to content
MakeWebGames

Recommended Posts

Posted

Okay yall gonna laugh at me but Im trying... I try to add where my users have to have a certain amount of stats before they can get exp. points to prevent people from getting super high levels wit no stats.

I get an error that I have an unexpected else.

Any way this is what I did this what was there.

 

if($odata['hp'] <= 0){$odata['hp']=0;$_SESSION['attackwon']=$_GET['ID'];$db->query("UPDATE users SET hp=0 WHERE userid={$_GET['ID']}");print "
[b]What do you want to do with {$odata['username']} now?[/b]

<form action='attackwon.php?ID={$_GET['ID']}' method='post'><input type='submit' STYLE='color: white;  background-color: red;' value='Mug Them' />  </form>  
 <form action='attackbeat.php?ID={$_GET['ID']}' method='post'><input type='submit' STYLE='color: white;  background-color: green;' value='Hospitalize Them' />  </form>  
<form action='attacktake.php?ID={$_GET['ID']}' method='post'><input type='submit' STYLE='color: black;  background-color: white;' value='Leave Them' /> </form>  




NB:If you not choose any of the option above you lose all your EXP point !  


If you and the enemy beaten are on the same battle ladder mug them to get points added to the ladder table !  


";

right after that I added

}else if ($odata['hp'] <= 0 and ($youdata['strength']+$youdata['guard']+$youdata['agility']) < ($youdata['level']*60000));{$odata['hp']=0;$_SESSION['attackwon']=$_GET['ID'];$db->query("UPDATE users SET hp=0 WHERE userid={$_GET['ID']}");print "
[b]What do you want to do with {$odata['username']} now?[/b]

<form action='attackwon.php?ID={$_GET['ID']}' method='post'><input type='submit' STYLE='color: white;  background-color: red;' value='Mug Them' />  </form>  
 <form action='attackbeat.php?ID={$_GET['ID']}' method='post'><input type='submit' STYLE='color: white;  background-color: green;' value='Hospitalize Them' />  </form>  


Before you can get anymore exp. you have to work on your stats.NB:If you not choose any of the option above you lose all your EXP point !  


If you and the enemy beaten are on the same battle ladder mug them to get points added to the ladder table !  


";}

This is the line where the error is I just posted the whole thing. unexpected else

else {//choose opp gun$eq=$db->query("SELECT i.* FROM  items i  WHERE i.itmid IN({$odata['equip_primary']}, {$odata['equip_secondary']})");if(mysql_num_rows($eq) == 0){$wep="Fists";$dam=(int)((((int) ($odata['strength']/$ir['guard']/100)) +1)*(rand(8000,12000)/10000));}else{$cnt=0;while($r=$db->fetch_row($eq)){$enweps[]=$r;$cnt++;}$weptouse=rand(0,$cnt-1);$wep=$enweps[$weptouse]['itmname'];$dam=(int) (($enweps[$weptouse]['weapon']*$odata['strength']/($youdata['guard']/1.5))*(rand(8000,12000)/10000));}$hitratio=max(10,min(60*$odata['agility']/$ir['agility'],95));if(rand(1,100) <= $hitratio)

 

If anyone has better way to do this that would be great also....

Posted

YUCK!

First of all, I would suggest making better use of whitespace. Cramming everything together does NOT make it run any faster.

Here is a copy of your first snippet with additional whitespace:

 

if($odata['hp'] <= 0)
{
$odata['hp']=0;$_SESSION['attackwon']=$_GET['ID'];
$db->query("UPDATE users SET hp=0 WHERE userid={$_GET['ID']}");
print "
[b]What do you want to do with {$odata['username']} now?[/b]


<form action='attackwon.php?ID={$_GET['ID']}' method='post'>
		<input type='submit' STYLE='color: white;  background-color: red;' value='Mug Them' /></form>  

<form action='attackbeat.php?ID={$_GET['ID']}' method='post'>
		<input type='submit' STYLE='color: white;  background-color: green;' value='Hospitalize Them' /></form>  

<form action='attacktake.php?ID={$_GET['ID']}' method='post'>
		<input type='submit' STYLE='color: black;  background-color: white;' value='Leave Them' /> </form>  


NB:If you not choose any of the option above you lose all your EXP point !  


		If you and the enemy beaten are on the same battle ladder mug them to get points added to the ladder table !";

 

See how much easier that is to read?

Now, on to the actual problem. You have a semicolon after your second else

 

}else if ($odata['hp'] <= 0 and ($youdata['strength']+$youdata['guard']+$youdata['agility']) < ($youdata['level']*60000)); <== Here is your problem

 

Get that out of there. PHP does accept inline conditionals, so you could have

 

if ( $var == 1) print "$var is one.";

 

or

 

if ($var == 1)
{
print "$var is one."
}

 

and both are valid.

Posted

This is a site for sharing knowledge, though I will admit there are some that seem to lord what they know over those who are still learning. Everyone has to start somewhere.

Semicolons can be killer. I don't feel ashamed admitting it, but I sometimes make the same mistake, though forgetting a semicolon or using a directive that is used by the proprietary code of my company's software.

FYI, by adding whitespace, that error became readily apparent.

Glad to help

Posted

My biggest problem is missing a ' or ` sometimes in a statement, query or echo type statement

be amazed how hard that key is to hit sometimes it would seem

i.e

mysql_query("SELECT `userid` FROM `users` WHERE `userid !=".$r['userid']."");

The above code would error and depending on how late it is I could stare at it forever and just NOT see it >,< I end up looking above and below that line to figure it out, especially if it's not a query and doesnt say "query error" lol

i.e

echo "blah blah';

can't count the number of times i've done that ><

Posted

A semicolon also signifies the end of a database query it's not "incorrect"

The reason the above statement won't work is because i'm missing a ` (Intentional) Neither of the above should work i was demonstrating a common error i make.

The 2nd example you are reffering to however was assuming the echo is between { } tags from an if statement, i'm just being lazy

It was an example of a common typo i do when I get in a hurry. lol. jeez

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...