Browser MMO Video #17

Location of the Videos
User avatar
hallsofvallhalla
Site Admin
Posts: 12026
Joined: Wed Apr 22, 2009 11:29 pm

Re: Video #17

Post by hallsofvallhalla »

yes.

Just make the image link to your battle page and add a url variable that states which creature

Code: Select all

<a href="battle.php?creature=goblin"><img scr="goblin_pic.png"></a>
then on battle just uses a get method to pull the creature

then query the creatures table by creature name
vertabrate
Posts: 5
Joined: Fri Jan 01, 2010 9:18 pm

Re: Video #17

Post by vertabrate »

Ah cheers mate.

I think i've customized the script so much i've deleted something and it's not working anymore to do that.

Hmmm will repair, thanks mate
Proud owner of RealmOfEnron
http://realmofenron.co.cc
User avatar
Zerk
Posts: 58
Joined: Wed Jan 20, 2010 2:59 am

Re: Video #17

Post by Zerk »

I have given up trying to solve this on my own, so I hope you guys can help me.

I get the following error after I click a stat to level up: Parse error: parse error in C:\wamp\www\void\levelup2.php on line 87
Line 87 is toward the bottom. I used a //comment to locate it.

Code: Select all

Levelup2.php

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


?>

<!--logo   -->
<?php


include_once 'phpinclude/logo.php';
?>



<?php
if (isset($_SESSION['player']))
{
  $player=$_SESSION['player'];
}
else
{
   include_once ('phpinclude/indexloginfalse.php');
}
include_once ('phpinclude/logoutbutton.php');
?>



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

include_once ('phpinclude/statpanel.php');

include_once ('phpinclude/deathcheck.php');

$playerid = $playerinfo3['id'];
?>


<div id="table">
<?php
  $expneeded = ($playerinfo3['level'] * 100) * $playerinfo3['level'];
   if ($playerinfo3['exper'] >= $expneeded)
   {
     $stat = $_GET['stat'];
     
     switch($stat)
     {
              case 'att';
       $statname = 'attack';
       $mod = 1;
       break;
       
              case 'def';
       $statname = 'defense';
       $mod = 1;
       break;
       
              case 'hp';
       $statname = 'maxhp';
       $mod = 5;
       break;
       
              case 'sp';
       $statname = 'maxsp';
       $mod = 5;
       break;
     }

     $updateplayer="update players set `$statname`=`$statname`+'$mod',level=level+1 where id='$playerid'";
     mysql_query=($updateplayer) or die("Could not update player");               //////////////This is line 87
     echo "You are now level " . $playerinfo3['level'] . "! <br><br><a href='index.php'>Return to town</a>";


   }
   else
   {
     echo "You do not have enough experience to level up right now! <br><br> <a href='index.php'>Go back</a>";
   }



?>
</div>
Coding - Unity3d JS, PHP, and small amount of C#.
Art stuff - GIMP, Blender
User avatar
Jackolantern
Posts: 10891
Joined: Wed Jul 01, 2009 11:00 pm

Re: Video #17

Post by Jackolantern »

For one, you need to change your switch statement. You need to change your cases to case labels:

Code: Select all

switch($stat)
     {
              case 'att':
       $statname = 'attack';
       $mod = 1;
       break;
       
              case 'def':
       $statname = 'defense';
       $mod = 1;
       break;
       
              case 'hp':
       $statname = 'maxhp';
       $mod = 5;
       break;
       
              case 'sp':
       $statname = 'maxsp';
       $mod = 5;
       break;
     }
Right now, after each "case 'x'", you have a semicolon. Those need to be changed to full colons.

Also, is that SQL statement the way you want it?

Code: Select all

$updateplayer="update players set `$statname`=`$statname`+'$mod',level=level+1 where id='$playerid'";
So say you have columns with Strength, Dexterity and Intelligence (example stats). You are going to save in that column "Strength12"? The value you are storing in that field is the name of the column plus what I assume is a number ($mod). You may want to check your db and see if that is how you have it set up (it would need to be some kind of char or text field).

EDIT: And wait a second, are those backticks surrounding the $statname in the SQL statement? You need to use single quotes (' ' ' ' ') and not backticks (` ` ` ` `) as far as I know. The backticks are most likely the cause of the parse error. The switch statement would likely just cause a logic error, and the SQL statement a SQL error if that is not how your fields are set up. However, backticks where they are not supposed to go would cause a parse error.
The indelible lord of tl;dr
User avatar
hallsofvallhalla
Site Admin
Posts: 12026
Joined: Wed Apr 22, 2009 11:29 pm

Re: Video #17

Post by hallsofvallhalla »

backticks sometimes are needed to tell PHP to use the actual variable and not the variable name. usually though its only needed when naming the table name. This way if $statname = strength, it won't add strength + 12 but will add the variable assigned to strength to 12.
User avatar
Jackolantern
Posts: 10891
Joined: Wed Jul 01, 2009 11:00 pm

Re: Video #17

Post by Jackolantern »

hallsofvallhalla wrote:backticks sometimes are needed to tell PHP to use the actual variable and not the variable name. usually though its only needed when naming the table name. This way if $statname = strength, it won't add strength + 12 but will add the variable assigned to strength to 12.
Ahhh, so kind of like a basic pointer, then. I didn't know you could do that.

Then the only possible parse error I could see is using the semicolon in the switch() statement instead of a colon. However, I am not sure if that is really a parse error, or only a short-circuit.
The indelible lord of tl;dr
User avatar
hallsofvallhalla
Site Admin
Posts: 12026
Joined: Wed Apr 22, 2009 11:29 pm

Re: Video #17

Post by hallsofvallhalla »

yes it is strange, i still believe it has something to do with the select statement and the variables but not sure where. Try commenting out certain things and see what makes it work.
User avatar
Zerk
Posts: 58
Joined: Wed Jan 20, 2010 2:59 am

Re: Video #17

Post by Zerk »

I commented the

Code: Select all

mysql_query=($updateplayer) or die("Could not update player");
And it worked....but, because it doesn't have that line, the player is not updated...I'll try using colons instead of semi-colons. I'll edit after I try


EDIT: using colons didn't change anything. I get the same parse error.


EDIT2: went ahead and did vid 18. Great video series, Halls. I have learned a lot. I think I'll try to start working on player-to-player interaction^^
Coding - Unity3d JS, PHP, and small amount of C#.
Art stuff - GIMP, Blender
User avatar
Jackolantern
Posts: 10891
Joined: Wed Jul 01, 2009 11:00 pm

Re: Video #17

Post by Jackolantern »

Hmmm...that is really strange, because I don't see a problem with that line of code. However, I don't use mysql_query type functions. I use mysqli. You could try altering it like this for the hell of it:

Code: Select all

$query = "your query string here";
$qResults = mysqli_query($db, $query);
$qArray = mysqli_fetch_array($qResults);
You will probably notice that the only major difference is that you specify the database connection resource as the first of two parameters when you run the query. Mysqli is a bit more optimized than mysql as a function set anyway.
The indelible lord of tl;dr
User avatar
Zerk
Posts: 58
Joined: Wed Jan 20, 2010 2:59 am

Re: Video #17

Post by Zerk »

I get an even weirder message and I have no idea to fix it (never seen this error).

Warning: mysqli_query() expects parameter 1 to be mysqli, resource given in C:\wamp\www\void\levelup2.php on line 99

Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, null given in C:\wamp\www\void\levelup2.php on line 100

Code: Select all

     $query = "update players set `$statname`=`$statname`+'$mod',level=level+1 where id='$playerid'";
$qResults = mysqli_query($db/*db*/, $query);
$qArray = mysqli_fetch_array($qResults);
lol...this is frustrating.
Coding - Unity3d JS, PHP, and small amount of C#.
Art stuff - GIMP, Blender
Post Reply

Return to “Older Browser MMO Videos”