little problem....

Place for questions and answers for all newcomers and new coders. This is a free for all forum, no question is too stupid and to noob.
Post Reply
User avatar
project69
Posts: 22
Joined: Mon Jan 09, 2012 3:41 pm

little problem....

Post by project69 »

hey all,

i'm following hallsofvallhalla's tutorial to create a little Browser MMO..
which is kinda nice! :D

ok so i'm at the part 4b, and everything is right no error in the code and the page work...
but it seems as my creatures doesn't exist...

Image

it say's "Player1" but do not say's creature name...............
A new Game Project has been started and is currently looking for coders & designers.
Here is the Topic: New Project
Or, just PM me if you're interested! :D
User avatar
hallsofvallhalla
Site Admin
Posts: 12023
Joined: Wed Apr 22, 2009 11:29 pm

Re: little problem....

Post by hallsofvallhalla »

we need to see your code

also I do not recommend doing the code until around video 14 but up to you.
User avatar
project69
Posts: 22
Joined: Mon Jan 09, 2012 3:41 pm

Re: little problem....

Post by project69 »

here is the code

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);

if (isset($_GET['creature']))
{
  $creature=$_GET['creature'];
  $creatureinfo="SELECT * from players 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.";
  exit;
}

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

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


///////////////////player turn///////////////////////

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

echo $playerinfo3['name'] . "'s Attack 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 where name='$creature' limit 1";
     mysql_query($updatecreature) or die("Could not update creature");
          
          echo "<a href='battle.php>Go back";
          exit;
   }
   $updatecreature="update creatures set hpoints='$newcreaturehp' where name='$creature' limit 1";
   mysql_query($updatecreature) or die("Could not update creatures");
}
else
{
   echo $playerinfo3['name'] . " misses!<br>";
}
////////////////////////////creature 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);
   $newplayerehp = $playerehp - $creaturedamage;
  echo "For " . $creaturedamage . " points of damage. <br>";
   if ($newplayerehp < 1)
   {
      echo $playerinfo3['name'] . " has been killed<br>";
      echo "<a href='gameover.php>Continue";
      exit;
   }
   $updateplayer="update players set hpoints='$newplayerhp' where name='player1'";
   mysql_query($updateplayer) or die("Could not update player");
}
else
{
  echo $creature . "misses!";
}
echo "<br><br><a href='battle.php?creature=$creature>Battle Again!";
?>
Also,
the "Battle Again" is not there...

why do you recommend me to start codes around video 14?
A new Game Project has been started and is currently looking for coders & designers.
Here is the Topic: New Project
Or, just PM me if you're interested! :D
User avatar
MikeD
Posts: 294
Joined: Thu Sep 08, 2011 4:28 am

Re: little problem....

Post by MikeD »

Code: Select all

  $creatureinfo="SELECT * from players where name='$creature'";
$creatureinfo2=mysql_query($creatureinfo) or die("Could not get the creature you were fighting!");
$creatureinfo3=mysql_fetch_array($creatureinfo2);
It looks like your trying to pull a creature from the players table.

Not sure how your DB is set up, but it should be something like this.

Code: Select all

 $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);
User avatar
project69
Posts: 22
Joined: Mon Jan 09, 2012 3:41 pm

Re: little problem....

Post by project69 »

Thank you Mark,
it works now.

But it still dont show up the "battle again" option.
A new Game Project has been started and is currently looking for coders & designers.
Here is the Topic: New Project
Or, just PM me if you're interested! :D
User avatar
MikeD
Posts: 294
Joined: Thu Sep 08, 2011 4:28 am

Re: little problem....

Post by MikeD »

project69 wrote:Thank you Mark,
it works now.

But it still dont show up the "battle again" option.
Looks like you forgot a single quote.

Code: Select all

echo "<br><br><a href='battle.php?creature=$creature'>Battle Again!";
User avatar
project69
Posts: 22
Joined: Mon Jan 09, 2012 3:41 pm

Re: little problem....

Post by project69 »

lol yeah.. :P

but why should i start codes from video 14 only?
i miss all the starter things? So how can i add all things in my db if i skip this..

Also, i'm at Part 5 now and my login.php work but when i hit "Login" nothing happens...

heres my login.php code:

Code: Select all

<from method="POST" action="authenticate.php">
Username: <input type="text" name="player" size="21">
Password: <input type="password" name="password" size="21" mask="x">
<br>
<input type="submit" value="Login" name="submit">
here is my authenticate.php code:

Code: Select all

<?php
include_once 'connect.php';
session_start();

if (isset($_POST['submit']))
{
  $player=$_POST['player'];
  $password=$_POST['password'];
  $player=strip_tags($player);
  $password=strip_tags($password);
  $password=md5($password);

  $query = "select name,password from players where name='$player' and '$password'";
  $result = mysql_query($query) or die("Could not query players");
  $result2 = mysql_fetch_array($result);
  if($result2)
  {
   $_SESSION['player']=$player;
              
   echo "<big>Logged in successfully<br>";
   echo "<a href='battle.php'>Continue</a></big>>";
  }
  else
  {
   echo "<big>Wrong username or password, <a href='login.php'>Try Again</a></big>";
  }
}
?>
A new Game Project has been started and is currently looking for coders & designers.
Here is the Topic: New Project
Or, just PM me if you're interested! :D
User avatar
MikeD
Posts: 294
Joined: Thu Sep 08, 2011 4:28 am

Re: little problem....

Post by MikeD »

You misspelled Form, and forgot to close the form.

Code: Select all

<form method="POST" action="authenticate.php">
Username: <input type="text" name="player" size="21" />
Password: <input type="password" name="password" size="21" mask="x" />
<br>
<input type="submit" value="Login" name="submit" />
</form>
Also on your authenticate, change

Code: Select all

  $query = "select name,password from players where name='$player' and '$password'";
to

Code: Select all

  $query = "select name,password from players where name='$player' and password='$password'";
User avatar
project69
Posts: 22
Joined: Mon Jan 09, 2012 3:41 pm

Re: little problem....

Post by project69 »

thanks again...
the error was to change "form"... :P
A new Game Project has been started and is currently looking for coders & designers.
Here is the Topic: New Project
Or, just PM me if you're interested! :D
User avatar
project69
Posts: 22
Joined: Mon Jan 09, 2012 3:41 pm

Re: little problem....

Post by project69 »

another error.

i'm at part 6 now and it says me:
Parse error: syntax error, unexpected ';' in C:\wamp\www\tutorial\attack.php on line 75
the error is on this line:
$thirdmod = ($secondmod / 100 * $creatureinfo3['exper'];

Code: Select all

            if ($playerinfo3['level'] > $creatureinfo3['level'])
            {
             $firstmod = $playerinfo3['level'] - $creatureinfo3['level'];
             $secondmod = $firstmod * 10 ;
             if ($secondmod > 90){$secondmod = 90;}
             $thirdmod = ($secondmod /  100 * $creatureinfo3['exper'];
             $totalexper =$creatureinfo3['exper'] - $thirdmod;
            }
            else
            {
             $firstmod = $creatureinfo3['level'] - $playerinfo3['level'];
             $secondmod = $firstmod * 10 ;
             if ($secondmod > 90){$secondmod = 90;}
             $thirdmod = ($secondmod /  100 * $creatureinfo3['exper'];
             $totalexper =$creatureinfo3['exper'] + $thirdmod;
            }

echo "<br><br><big>You gain " . $totalexper . " experience.</br></big><br>";
$updateplayer="update players set exper=exper+'$totalexper' where name='$player'";
mysql_query($updateplayer) or die("Could not update player");


why it says that my ";" is unexpected? :shock:

_______

Fixed
i've forgot ")"... :P
i really like these tutorials as it helps me to learn a little bit.
A new Game Project has been started and is currently looking for coders & designers.
Here is the Topic: New Project
Or, just PM me if you're interested! :D
Post Reply

Return to “Beginner Help and Support”