Jump to content
MakeWebGames

Recommended Posts

Posted

I was trying to make a gym where the higher you are in a stat the more you would gain. I was trying to code this and got an error. This is the code for that area in question

error "Parse error: syntax error, unexpected '{' in /bla/db/my_html/superenergygym.php on line 25

" When I removed the {s I get another error which is

Parse error: syntax error, unexpected T_VARIABLE in /bla/db/my_html/superenergygym.php on line 26 I have spent time into fixing it i just don't know what exactly is wrong. $boost is used later in the gym equation so I don't have to format it for each stat.

$statnames=array(
'Strength' => 'strength',
'Agility' => 'agility',
'Guard' => 'guard',
'Labour' => 'labour');
$_POST['amnt']=abs((int) $_POST['amnt']);
if(!$ir['jail'])
{
print "<h3>Super energy Gym</h3><hr />";
}
else
{
 print "<h3>Super energy Jail Gym</h3><hr />";
}
if($_POST['stat'] && $_POST['amnt'])
{
 $stat=$statnames[$_POST['stat']];
 if(!$stat)
 {
   die("This stat cannot be trained.");
if($_POST['stat']=strength
{
$boost={$ir['strength']}
{
else

if($_POST['stat']=agility
{
$boost={$ir['agility']}
{
else

if($_POST['stat']=guard
{
$boost={$ir['guard']}
{
else

if($_POST['stat']=labour
{
$boost={$ir['labour']}
{
}
}
}

Any help would be appreciated

Posted

Re: V2 a custom gym problem

:-o That is the worst syntax I have ever seen.

 

$statnames=array(
'Strength' => 'strength',
'Agility' => 'agility',
'Guard' => 'guard',
'Labour' => 'labour');
$_POST['amnt']=abs((int) $_POST['amnt']);
if(!$ir['jail'])
{
print "<h3>Super energy Gym</h3><hr />";
}
else
{
print "<h3>Super energy Jail Gym</h3><hr />";
}
if($_POST['stat'] && $_POST['amnt'])
{
$stat=$statnames[$_POST['stat']];
if($_POST['stat']=='strength')
{
	$boost=$ir['strength'];
}
else if($_POST['stat']=='agility')
{
	$boost=$ir['agility'];
}
else if($_POST['stat']=='guard')
{
	$boost=$ir['guard'];
}
else if($_POST['stat']=='labour')
{
	$boost=$ir['labour'];
}
else
{
	die("Invalid Stat");
}

}


You may have to add some more brackets at the end, but this section is properly formatted.

However I don't think that'll work. I would do it this way.:

 

$_POST['amnt']=abs((int) $_POST['amnt']);
if(!$ir['jail'])
{
print "<h3>Super energy Gym</h3><hr />";
}
else
{
print "<h3>Super energy Jail Gym</h3><hr />";
}
if($_POST['stat'] && $_POST['amnt'])
{
if($_POST['stat']=='Strength')
{
	$boost=$ir['strength'];
}
else if($_POST['stat']=='Agility')
{
	$boost=$ir['agility'];
}
else if($_POST['stat']=='Guard')
{
	$boost=$ir['guard'];
}
else if($_POST['stat']=='Labour')
{
	$boost=$ir['labour'];
}
else
{
	die("Invalid Stat");
}

}
Posted

Re: V2 a custom gym problem

Yea I know except one problem I just ran into is

QUERY ERROR: Unknown column '' in 'field list'
Query was UPDATE `userstats` SET `` = `` + 0 WHERE `userid` = 1

I'm fairly sure it was just me plugging stuff in wrong... but than again its like 2:20 a.m here so it might be that heres the whole page

<?php
$macropage="superenergygym.php";
include "globals.php";
$statnames=array(
'Strength' => 'strength',
'Agility' => 'agility',
'Guard' => 'guard',
'Labour' => 'labour');
$_POST['amnt']=abs((int) $_POST['amnt']);
if(!$ir['jail'])
{
print "<h3>Super energy Gym</h3><hr />";
}
else
{
print "<h3>Super energy Jail Gym</h3><hr />";
}
if($_POST['stat'] && $_POST['amnt'])
{
if($_POST['stat']=='Strength')
{
	$boost=$ir['strength'];
}
else if($_POST['stat']=='Agility')
{
	$boost=$ir['agility'];
}
else if($_POST['stat']=='Guard')
{
	$boost=$ir['guard'];
}
else if($_POST['stat']=='Labour')
{
	$boost=$ir['labour'];
}
else
{
	die("Invalid Stat");
}



}

if($_POST['amnt'] > ($ir['superenergy'])/10)
 {
   print("You do not have enough super energy to train that much.<hr />");
 }
 else
 {
   $gain=0;
   for($i=0; $i<$_POST['amnt']; $i++)
   {

$gain+=(rand(1,3)/rand(450,650)*rand(749,751)*rand(800,1000)*$boost*1000*$ir['will']*$boost*1/4+92)/450; 
$ir['will']-=rand(1,3);

if($ir['will'] < 0) { $ir['will']=0; }
   }


   if($ir['jail']) { $gain/=2; }
   $db->query("UPDATE `userstats` SET `{$stat}`=`{$stat}` + $gain WHERE `userid` = $userid");
 $db->query("UPDATE `users` SET `exp` = (`exp`+$gain/40) WHERE `userid` = $userid");

   $db->query("UPDATE `users` SET `will` = {$ir['will']}, superenergy = superenergy - ({$_POST['amnt']}*10) WHERE `userid` = $userid");
   $inc=$ir[$stat]+$gain;
   $inc2=$ir['superenergy']-($_POST['amnt']*10);
   if($stat=="strength")
   {
     print "You begin lifting some weights.

     You have gained {$gain} strength by doing {$_POST['amnt']} sets of weights. Note that it takes 10 super energy per one train

     You now have {$inc} strength and {$inc2} super energy left. Note that it takes 10 super energy per one train";
   }
   elseif($stat=="agility")
   {
     print "You begin running on a treadmill.

     You have gained {$gain} agility by doing {$_POST['amnt']} minutes of running. Note that it takes 10 super energy per one train

     You now have {$inc} agility and {$inc2} super energy left. Note that it takes 10 super energy per one tran";
   }
   elseif($stat=="guard")
   {
     print "You jump into the pool and begin swimming.

     You have gained {$gain} guard by doing {$_POST['amnt']} minutes of swimming.

     You now have {$inc} guard and {$inc2} super energy left. Note that it takes 10 super energy per one train";
   }
   elseif($stat=="labour")
   {
     print "You walk over to some boxes filled with gym equipment and start moving them.

     You have gained {$gain} labour by moving {$_POST['amnt']} boxes.

     You now have {$inc} labour and {$inc2} super energy left. Note it takes 10 super energy per one train.";
   }
   print "<hr />";
   $ir['superenergy']-=$_POST['amnt'];
   $ir[$stat]+=$gain;
 }

$ir['strank']=get_rank($ir['strength'],'strength');
$ir['agirank']=get_rank($ir['agility'],'agility');
$ir['guarank']=get_rank($ir['guard'],'guard');
$ir['labrank']=get_rank($ir['labour'],'labour');
print "Choose the stat you want to train and the times you want to train it.

You can train one time per 10 super energy.<hr />
<form action='superenergygym.php' method='post'>
Stat: <select type='dropdown' name='stat'>
<option style='color:red;' value='Strength'>Strength (Have {$ir['strength']}, Ranked {$ir['strank']})
<option style='color:blue;' value='Agility'>Agility (Have {$ir['agility']}, Ranked {$ir['agirank']})
<option style='color:green;' value='Guard'>Guard (Have {$ir['guard']}, Ranked {$ir['guarank']})
<option style='color:brown;' value='Labour'>Labour (Have {$ir['labour']}, Ranked {$ir['labrank']})
</select>

Times to train Note this amount is the max you can at full super energy: <input type='text' name='amnt' value='{$ir['maxsuperenergy']}' />

<input type='submit' value='Train' /></form>";
$h->endpage();
?>

I don't think the rest could've gotten too messed up though from just revamping it from the normal gym.

Posted

Re: V2 a custom gym problem

well its the updating stats.

QUERY ERROR: Unknown column '' in 'field list'
Query was UPDATE `userstats` SET ``=`` + 0 WHERE `userid` = 1

. I know I'm trying to get it similar to the tc gym as far as effect wise. Yes I'll trial and error to make the real formula fit my game though I just mean the stat gain by it.

Edit: I compared with my gym.php and the query for that is ok. What could be wrong then?

Posted

Re: V2 a custom gym problem

To fix just put the sum outside the query.

 

  $db->query("UPDATE `users` SET `exp` = (`exp`+$gain/40) WHERE `userid` = $userid");

to

 $insert=$gain/40;
$db->query("UPDATE `users` SET `exp` +={$insert} WHERE `userid` = {$userid}");

 

I think that would fix it, how about printing the $gain first to check it's a value.

Posted

Re: V2 a custom gym problem

well that was strange... well I guess the next thing I'm going to pull off is just going to customize the gym even more. I'll let everyone know how it goes in a while.

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...