Browser MMO Video #4

Location of the Videos
Rastan
Posts: 126
Joined: Tue Apr 13, 2010 1:48 am

Re: Video #4

Post by Rastan »

My guess is

Code: Select all

mysql_query[$updatepokemon];
///should be ///
mysql_query($updatepokemon);

///I don't know if you can use [] in place of ()

///other than that you need to close your php 
?>
Smuds
Posts: 2
Joined: Mon Jul 05, 2010 12:10 am

Re: Video #4

Post by Smuds »

Rastan wrote:My guess is

Code: Select all

mysql_query[$updatepokemon];
///should be ///
mysql_query($updatepokemon);

///I don't know if you can use [] in place of ()

///other than that you need to close your php 
?>
I just went and did both of those, and all it did was move the error to line 44...

Thanks anyways, because due to my stupidness, I did forget that close PHP thing :|.

EDIT: I went through the code, found a few errors in the coding, but now that I fixed some of it I get a new error :|.

Code: Select all

<?php
include 'connet.php';

$playerinfo="SELECT * from players where name='player1'";
$playerinfo2=mysql_query($playerinfo) or die ("could not get player stats!");
$playerinfo3=mysql_fetch_arra($playerinfo2);

if (isset($_GET['pokemon']))
{
$pokemon=$_GET['pokemon'];
$pokemoninfo="SELECT * from pokemon where name = '$pokemon'";
$pokemoninfo2=mysql_query($pokemoninfo) or die("could not get the pokemon you were fighting!");
$pokemoninfo3=mysql_fetch_array($pokemoninfo2);

}
else
{
  echo "<a href='battle.php'>No Pokemon selected. Go Back!";
  exit;
}
$playerhp = $playerinfo3['hpoints'];
$playerattack = $playerinfo3['attack'];
$playerdefense = $playerinfo3['defense'];

$pokemonhp = $pokemoninfo3['hpoints'];
$pokemonattack = $pokemoninfo3['attack'];
$pokemondefense = $pokemoninfo3['defense'];
//Players Turn
echo "<u>" . $playerinfo3['name'] . "'s Attack </u>";
$playerattack = rand(1,15) * (2*$playerattack) - ($pokemondefence);
if ($playerattack < 0)
{
  $playerattack = 0;
}
if ($playerattack < 1)
{
  echo 'Your attack misses!';
}
$newpokemonhp = $pokemonhp - $playerattack
if ($newpokemonhp < 1) /////////////////////////////////////////////LINE 40
{
  echo "You have defeated this pokemon and made it faint <br />";
  <a href='battle.php'>Go Back;
  exit;
       }
      $updatepokemon='update creatures set hpoints'='$newpokemonhp' where name='$pokemon';
      mysql_query($updatepokemon);
    }
?>
Parse error: parse error in C:\wamp\www\New Folder\attack.php on line 40
Rastan
Posts: 126
Joined: Tue Apr 13, 2010 1:48 am

Re: Video #4

Post by Rastan »

It's not that it moves an error most of the time. It's just found another error usually unless you blatantly make the possible problem go to a new line for testing.

$newpokemonhp = $pokemonhp - $playerattack

needs to be
$newpokemonhp = $pokemonhp - $playerattack;

needs a ; on the end. Usually if you miss a ";" it will just tell you you got an error on the next line down that it reads. if you had if statements that don't currently apply in between and the like it can be tricky to find. Just gotta look and work out how the code is working in your head as you go.

Then on line 46 you have an extra apostrophe sitting after hpoints that doesn't seem to have a mate
Your next problem might be on line 48 I think you have a "}" that doesn't go to any other "{" I think you can just take out the one above it and be fine.

That's all I saw in it. I have not tried to run it as I don't have a database set for it.
Shihonoryu
Posts: 255
Joined: Sun Dec 12, 2010 7:30 am

Re: Video #4

Post by Shihonoryu »

I keep getting "could get a creature!"


Table Descending Action Records 1 Type Collation Size Overhead
creature Browse Structure Search Insert Empty Drop 2 MyISAM latin1_swedish_ci 2.0 KiB -
players Browse Structure Search Insert Empty Drop 2 MyISAM latin1_swedish_ci 2.1 KiB -
2 table(s) Sum 4 MyISAM latin1_swedish_ci 4.2 KiB 0 B

No spaces or anything


Code: Select all

<?php
include 'connect.php';




$playerinfo="SELECT * from players where name='player1'";
$playerinfo2=mysql_query($playerinfo) or die("could not get player stats!");
$playerinfo3=mysql_fetch_array($playerinfo2);

$playerhp = $playerinfo3['HP'];
$playerattack = $playerinfo3['Attack'];
$playerdefense = $playerinfo3['Defence'];

if (isset($_GET['creature']))
{
   $creature=$_GET['creature'];
   $creatureinfo="SELECT * from creatures where name = '$creature'";
$creatureinfo2=mysql_query($creatureinfo) or die("could not get the creature you were fighting!");
$creatureinfo3=mysql_fetch_array($creatureinfo2);

}
else
{
  $creatureinfo="SELECT * from creatures order by rand() limit 1";
$creatureinfo2=mysql_query($creatureinfo) or die("could get a creature!");
$creatureinfo3=mysql_fetch_array($creatureinfo2);
}

$creature = $creatureinfo3['name'];
$creaturehp = $creatureinfo3['hpoints'];
$creatureattack = $creatureinfo3['attack'];
$creaturedefense = $creatureinfo3['defense'];

/////player info
echo "<u> " . $playerinfo3['name'] . "</u><br>";
echo "Hit points = " . $playerhp . "<br>";
echo "Attack = " . $playerattack . "<br>";
echo "Defense = " . $playerdefense . "<br><br><br>";

///////creature info
echo "<u> " . $creatureinfo3['name'] . "</u><br>";
echo "Hit points = " . $creaturehp . "<br>";
echo "Attack = " . $creatureattack . "<br>";
echo "Defense = " . $creaturedefense . "<br><br><br>";

echo "<a href='attack.php?creature=$creature'>Attack!";

?>
alexander19
Posts: 180
Joined: Fri Apr 02, 2010 1:05 pm

Re: Video #4

Post by alexander19 »

I guess your "creatures" table is called "creature" ?

Code: Select all

creature Browse Structure Search Insert Empty Drop 2 MyISAM latin1_swedish_ci 2.0 KiB -
You can change :

Code: Select all

$creatureinfo="SELECT * from creatures order by rand() limit 1";
to:

Code: Select all

 $creatureinfo="SELECT * from creature order by rand() limit 1";
Hope this works.
Shihonoryu
Posts: 255
Joined: Sun Dec 12, 2010 7:30 am

Re: Video #4

Post by Shihonoryu »

Will this turn into being a true online game? because thats what im hoping to learn how to do by the end of the tutorial.
User avatar
hallsofvallhalla
Site Admin
Posts: 12026
Joined: Wed Apr 22, 2009 11:29 pm

Re: Video #4

Post by hallsofvallhalla »

yes of course. It is already a true online game. Just got to put it online. I will make some videos to show you how.
Shihonoryu
Posts: 255
Joined: Sun Dec 12, 2010 7:30 am

Re: Video #4

Post by Shihonoryu »

hallsofvallhalla wrote:yes of course. It is already a true online game. Just got to put it online. I will make some videos to show you how.
yes that would be awesome! thank you so much halls! i really cant wait to finish the series and be able to code efficiently in PhP so i can get more into game design which is my dream
pretender5552
Posts: 127
Joined: Mon Jan 03, 2011 5:38 am

Re: Video #4

Post by pretender5552 »

I keep getting it popping up and saying that it can't update creature

Code: Select all

<?php
include_once 'connect.php';
session_start();
  
if (isset($_SESSION['players']))
{
   $player=$_SESSION['players'];
}
else
{
  echo"Not logged in <br>";
  echo "<a href='login.php'>Login</a>";
  exit;
}

$playerinfo = "SELECT * from players where name='$player'";
$playerinfo2 = mysql_query ($playerinfo) or die ("Could not get player stats!");
$playerinfo3 = mysql_fetch_array ($playerinfo2);

if (isset($_GET['creatures']))
{
   $creature = $_GET['creatures'];
   $creatureinfo = "SELECT * from creatures where name = '$creature'";
   $creatureinfo2 = mysql_query($creatureinfo) or die ("could not get the creature you were fighting!");
   $creatureinfo3 = mysql_fetch_array($creatureinfo2);
}
else   
{
 echo "<a href='battle.php'>No Creature selected. Go Back!</a>";
 exit;
}

$playerhp = $playerinfo3['hitpoints'];
$playerattack = $playerinfo3['attack'];
$playerdefense = $playerinfo3['defense'];

$creature = $creatureinfo3['name'];
$creaturehp = $creatureinfo3['hitpoints'];
$creatureattack = $creatureinfo3['attack'];
$creaturedefense = $creatureinfo3['defense'];


///////////////////////players turn////////////////////

echo "<u> " . $playerinfo3['name'] . "'s Attack </u><br>";
$playerattack = rand(1,20) + $playerattack;
$creaturedefense = rand(1,20) + $creaturedefense;

echo $playerinfo3['name'] . "'s Attak roll is " . $playerattack . "<br>";
echo $creature . "'s Defense roll is " . $creaturedefense . "<br>";

if ($playerattack > $creaturedefense)
{
   echo $playerinfo3['name'] . " hits! <br>";
   $playerdamage = rand(1,6);
   $newcreaturehp = $creaturehp - $playerdamage;
   echo "For " . $playerdamage . " points of damage. <br>";
   if ($newcreaturehp < 1)
     {
        echo "The " . $creature . " has been killed";
        $updatecreature = " delete from creatures when name = '$creature' limit 1";
        mysql_query($updatecreature) or die ("Could not update creature");


     //////////////////////experience/////////////////////////////
        if ($playerinfo3['level'] - $creatureinfo3['level'])
        {
          $firstmod = $playerinfo3['level'] - $creatureinfo3['level'];
          $secondmod = $firstmod * 10;
          if ($secondmod > 90){$secondmod = 90;}
          $thirdmod = ($secondmod / 100) * $creatureinfo3['experience'];
          $totalexper =$creatureinfo3['experience'] - $thirdmod;
        }
        else
        {
          $firstmod = $creatureinfo3['level'] - $playerinfo3['level'];
          $secondmod = $firstmod * 10;
          if ($firstmod > 90){$secondmod = 90;}
          $thirdmod = ($secondmod / 100) * $creatureinfo3['experience'];
          $totalexper =$creatureinfo3['experience'] + $thirdmod;
        }
            $totalexper = (int)$totalexper;
            
             echo "<br><b><big>You gain " . $totalexper . " experience.</b></big><br>";
        $updateplayer="update player set experience=experience+'$totalexper' where name='$player'";
     mysql_query($updateplayer) or die ("Couldn't update player!");


        echo "<a href='battle.php'>Go Back";
        exit;
     }
     
 //////////////////////////////////////////////////////////
     $updatecreature="update creatures set hitpoints='$newcreaturehp' where name='$creature' limit 1";
  mysql_query($updatecreature) or die ("Couldn't update creature!<br>");
  }
  else
  {
         echo $playerinfo3['name'] . " miss!<br>";
}

//////////////////////creatures turn //////////////////

echo "<u> " . $creature . "'s Attack</u><br>";
$creatureattack = rand(1,20) + $creatureattack;
$playerdefense = rand(1,20) + $playerdefense;

echo $creature . "'s Attack roll is " . $creatureattack . "<br>";
echo $playerinfo3['name'] . "'s Defense roll is " . $playerdefense . "<br>";

if ($creatureattack > $playerdefense)
{
  echo $creature . " hits! <br>";
  $creaturedamage = rand(1,6);
   $newplayerhp = $playerhp - $creaturedamage;
   echo "For " . $creaturedamage . " points of damage. <br>";
   if ($newplayerhp < 1)
   {
      echo $playerinfo3['name'] . " has been killed<br>";
       echo "<a href='gameover.php'>Continue";
       exit;
       }
  $updateplayer="update players set hitpoints='newplayerhp' where name='$player'";
  mysql_query($updateplayer) or die ("Could not update player");
}
else
{
   echo $creature . " misses!";
}
echo "<br><br><a href='battle.php?creature=$creature'>'Battle Again!";
?>
djand3y93
Posts: 16
Joined: Tue Nov 02, 2010 6:20 pm

Re: Video #4

Post by djand3y93 »

Try to change in line 61 from this:

Code: Select all

$updatecreature = " delete from creatures when name = '$creature' limit 1";
to this:

Code: Select all

$updatecreature = " delete from creatures where name = '$creature' limit 1";
hope it works:D
Post Reply

Return to “Older Browser MMO Videos”