By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,053 Members | 1,192 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,053 IT Pros & Developers. It's quick & easy.

please help... this is for a php game development script

P: n/a
/// Were having serious problems with this script it's basically the
map script allowing player movement but the problem is in the QUERY
and if statements on the cell type. Any help will be much appreciated
thanks you

<?php
session_start ();
require_once "connect.php";

//Register all the variables
if (!$_SESSION['new_map']) {session_register('new_map');
$_SESSION['new_map'] = 22;}
if (!$_SESSION['old_map']) {session_register('old_map');
$_SESSION['old_map'] = 22;}
if (!$_SESSION['new_col']) {session_register('new_col');
$_SESSION['new_col'] = 0;}
if (!$_SESSION['new_row']) {session_register('new_row');
$_SESSION['new_row'] = 0;}
if (!$_SESSION['old_col']) {session_register('old_col');
$_SESSION['old_col'] = 0;}
if (!$_SESSION['old_row']) {session_register('old_row');
$_SESSION['old_row'] = 0;}
if (!$_SESSION['cell_type']) {session_register('cell_type');
$_SESSION['cell_type'] = 'A';}
if (!$_SESSION['townid']) {session_register('townid');
$_SESSION['townid'] = 0;}
if (!$_SESSION['is_town']) {session_register('is_town');
$_SESSION['is_town'] = 0;}
if (!$_SESSION['townmap']) {session_register('townmap');
$_SESSION['townmap'] = '';}

//Turn X&Y into Col&Row
$_SESSION['new_col'] = floor($_REQUEST['map_x'] / 20);
$_SESSION['new_row'] = floor($_REQUEST['map_y'] / 20);

//Movement by 1 cell only
if (($_SESSION['old_col']-$_SESSION['new_col'])>1) {
$_SESSION['new_col']=$_SESSION['old_col'];
$_SESSION['new_row']=$_SESSION['old_row'];
$_SESSION['new_map']=$_SESSION['old_map'];}
elseif (($_SESSION['new_col']-$_SESSION['old_col'])>1) {
$_SESSION['new_col']=$_SESSION['old_col'];
$_SESSION['new_row']=$_SESSION['old_row'];
$_SESSION['new_map']=$_SESSION['old_map'];}

if (($_SESSION['old_row']-$_SESSION['new_row'])>1) {
$_SESSION['new_col']=$_SESSION['old_col'];
$_SESSION['new_row']=$_SESSION['old_row'];
$_SESSION['new_map']=$_SESSION['old_map'];}
elseif (($_SESSION['new_row']-$_SESSION['old_row'])>1) {
$_SESSION['new_col']=$_SESSION['old_col'];
$_SESSION['new_row']=$_SESSION['old_row'];
$_SESSION['new_map']=$_SESSION['old_map'];}

//Answers the question - Do we change maps?
if (($_SESSION['old_col'] == 1) && ($_SESSION['new_col'] == 0)) {
$_SESSION['new_map'] = ($_SESSION['old_map'] - 10);
$_SESSION['new_col'] = 23;}
elseif (($_SESSION['old_col'] == 23) && ($_SESSION['new_col'] ==
24)) {
$_SESSION['new_map'] = ($_SESSION['old_map'] + 10);
$_SESSION['new_col'] = 1;}

if (($_SESSION['old_row'] == 1) && ($_SESSION['new_row'] == 0)) {
$_SESSION['new_map'] = ($_SESSION['old_map'] - 1);
$_SESSION['new_row'] = 13;}
elseif (($_SESSION['old_row'] == 13) && ($_SESSION['new_row'] ==
14)) {
$_SESSION['new_map'] = ($_SESSION['old_map'] + 1);
$_SESSION['new_row'] = 1;}

/// THE PROBLEM STARTS HERE AND IS SOMEWHERE BELOW!
//Query the Database
$query = "SELECT type FROM map WHERE map_file = " .
$_SESSION['new_map'] . " AND col = " . $_SESSION['new_col'] . " AND
row = " . $_SESSION['new_row'];
$result = mysql_query($query) or die ("Error in query: $query. " .
mysql_error());
$db_cell_type = mysql_fetch_array($result)

//Evaluate the Cell Type
if ($db_cell_type['type']=='W'){
$_SESSION['new_col']=$_SESSION['old_col'];
$_SESSION['new_row']=$_SESSION['old_row'];
$_SESSION['new_map']=$_SESSION['old_map'];
$_SESSION['celltype']='W';}
elseif($db_cell_type['type']=='T'){
$query2 = "SELECT townID FROM map WHERE map_file = " .
$_SESSION['new_map'] . " AND col = " . $_SESSION['new_col'] . " AND
row = " . $_SESSION['new_row'];
$db_result2 = @mysql_query($query2);
$db_townid = mysql_fetch_array($db_result2);
$_SESSION['townID'] = $db_townid;
$_SESSION['is_town'] = 1;
$_SESSION['celltype']='T';}
else {
$_SESSION['old_col']=$_SESSION['new_col'];
$_SESSION['old_row']=$_SESSION['new_row'];
$_SESSION['old_map']=$_SESSION['new_map'];
$_SESSION['celltype']='L';}

?>

<!-- frames -->
<frameset cols="510,*">
<frame name="map" src="map.php?' . SID . '">
<frame name="interact" src="interact.php?' . SID . '">
</frameset>
Jul 17 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
On 3 Apr 2004 09:58:46 -0800, sk*******@yahoo.com (josh dismukes) wrote:
/// Were having serious problems with this script it's basically the
map script allowing player movement but the problem is in the QUERY
and if statements on the cell type. Any help will be much appreciated
thanks you
<snip>/// THE PROBLEM STARTS HERE AND IS SOMEWHERE BELOW!
What problem? How do you know it's somewhere below? What happens? What did you
expect to happen? etc.
//Query the Database
$query = "SELECT type FROM map WHERE map_file = " .
$_SESSION['new_map'] . " AND col = " . $_SESSION['new_col'] . " AND
row = " . $_SESSION['new_row'];
$result = mysql_query($query) or die ("Error in query: $query. " .
mysql_error());
$db_cell_type = mysql_fetch_array($result)

//Evaluate the Cell Type
if ($db_cell_type['type']=='W'){
$_SESSION['new_col']=$_SESSION['old_col'];
$_SESSION['new_row']=$_SESSION['old_row'];
$_SESSION['new_map']=$_SESSION['old_map'];
$_SESSION['celltype']='W';}
elseif($db_cell_type['type']=='T'){
$query2 = "SELECT townID FROM map WHERE map_file = " .
$_SESSION['new_map'] . " AND col = " . $_SESSION['new_col'] . " AND
row = " . $_SESSION['new_row'];
$db_result2 = @mysql_query($query2);
$db_townid = mysql_fetch_array($db_result2);
$_SESSION['townID'] = $db_townid;
$_SESSION['is_town'] = 1;
$_SESSION['celltype']='T';}
else {
$_SESSION['old_col']=$_SESSION['new_col'];
$_SESSION['old_row']=$_SESSION['new_row'];
$_SESSION['old_map']=$_SESSION['new_map'];
$_SESSION['celltype']='L';}

?>

<!-- frames -->
<frameset cols="510,*">
<frame name="map" src="map.php?' . SID . '">
<frame name="interact" src="interact.php?' . SID . '">
</frameset>


--
Andy Hassall <an**@andyh.co.uk> / Space: disk usage analysis tool
http://www.andyh.co.uk / http://www.andyhsoftware.co.uk/space
Jul 17 '05 #2

P: n/a
On 3 Apr 2004 09:58:46 -0800, sk*******@yahoo.com (josh dismukes)
wrote:
/// Were having serious problems with this script it's basically the
map script allowing player movement but the problem is in the QUERY
and if statements on the cell type. Any help will be much appreciated
thanks you

<?php
session_start ();
require_once "connect.php";

//Register all the variables
if (!$_SESSION['new_map']) {session_register('new_map');
$_SESSION['new_map'] = 22;}
if (!$_SESSION['old_map']) {session_register('old_map');
$_SESSION['old_map'] = 22;}
if (!$_SESSION['new_col']) {session_register('new_col');
$_SESSION['new_col'] = 0;}
if (!$_SESSION['new_row']) {session_register('new_row');
$_SESSION['new_row'] = 0;}
if (!$_SESSION['old_col']) {session_register('old_col');
$_SESSION['old_col'] = 0;}
if (!$_SESSION['old_row']) {session_register('old_row');
$_SESSION['old_row'] = 0;}
if (!$_SESSION['cell_type']) {session_register('cell_type');
$_SESSION['cell_type'] = 'A';}
if (!$_SESSION['townid']) {session_register('townid');
$_SESSION['townid'] = 0;}
if (!$_SESSION['is_town']) {session_register('is_town');
$_SESSION['is_town'] = 0;}
if (!$_SESSION['townmap']) {session_register('townmap');
$_SESSION['townmap'] = '';}

//Turn X&Y into Col&Row
$_SESSION['new_col'] = floor($_REQUEST['map_x'] / 20);
$_SESSION['new_row'] = floor($_REQUEST['map_y'] / 20);

//Movement by 1 cell only
if (($_SESSION['old_col']-$_SESSION['new_col'])>1) {
$_SESSION['new_col']=$_SESSION['old_col'];
$_SESSION['new_row']=$_SESSION['old_row'];
$_SESSION['new_map']=$_SESSION['old_map'];}
elseif (($_SESSION['new_col']-$_SESSION['old_col'])>1) {
$_SESSION['new_col']=$_SESSION['old_col'];
$_SESSION['new_row']=$_SESSION['old_row'];
$_SESSION['new_map']=$_SESSION['old_map'];}

if (($_SESSION['old_row']-$_SESSION['new_row'])>1) {
$_SESSION['new_col']=$_SESSION['old_col'];
$_SESSION['new_row']=$_SESSION['old_row'];
$_SESSION['new_map']=$_SESSION['old_map'];}
elseif (($_SESSION['new_row']-$_SESSION['old_row'])>1) {
$_SESSION['new_col']=$_SESSION['old_col'];
$_SESSION['new_row']=$_SESSION['old_row'];
$_SESSION['new_map']=$_SESSION['old_map'];}

//Answers the question - Do we change maps?
if (($_SESSION['old_col'] == 1) && ($_SESSION['new_col'] == 0)) {
$_SESSION['new_map'] = ($_SESSION['old_map'] - 10);
$_SESSION['new_col'] = 23;}
elseif (($_SESSION['old_col'] == 23) && ($_SESSION['new_col'] ==
24)) {
$_SESSION['new_map'] = ($_SESSION['old_map'] + 10);
$_SESSION['new_col'] = 1;}

if (($_SESSION['old_row'] == 1) && ($_SESSION['new_row'] == 0)) {
$_SESSION['new_map'] = ($_SESSION['old_map'] - 1);
$_SESSION['new_row'] = 13;}
elseif (($_SESSION['old_row'] == 13) && ($_SESSION['new_row'] ==
14)) {
$_SESSION['new_map'] = ($_SESSION['old_map'] + 1);
$_SESSION['new_row'] = 1;}

/// THE PROBLEM STARTS HERE AND IS SOMEWHERE BELOW! IT'S SUPPOSED TO PULL THE MAP TYPE FOR THE DB, BUT IT'S PULLING THE
ELSE STATEMENT FOR EXAMPLE GO TO SEVEREDREALM.NET/TESTING

//Query the Database
$query = "SELECT type FROM map WHERE map_file = " .
$_SESSION['new_map'] . " AND col = " . $_SESSION['new_col'] . " AND
row = " . $_SESSION['new_row'];
$result = mysql_query($query) or die ("Error in query: $query. " .
mysql_error());
$db_cell_type = mysql_fetch_array($result)

//Evaluate the Cell Type
if ($db_cell_type['type']=='W'){
$_SESSION['new_col']=$_SESSION['old_col'];
$_SESSION['new_row']=$_SESSION['old_row'];
$_SESSION['new_map']=$_SESSION['old_map'];
$_SESSION['celltype']='W';}
elseif($db_cell_type['type']=='T'){
$query2 = "SELECT townID FROM map WHERE map_file = " .
$_SESSION['new_map'] . " AND col = " . $_SESSION['new_col'] . " AND
row = " . $_SESSION['new_row'];
$db_result2 = @mysql_query($query2);
$db_townid = mysql_fetch_array($db_result2);
$_SESSION['townID'] = $db_townid;
$_SESSION['is_town'] = 1;
$_SESSION['celltype']='T';}
else {
$_SESSION['old_col']=$_SESSION['new_col'];
$_SESSION['old_row']=$_SESSION['new_row'];
$_SESSION['old_map']=$_SESSION['new_map'];
$_SESSION['celltype']='L';}

?>

<!-- frames -->
<frameset cols="510,*">
<frame name="map" src="map.php?' . SID . '">
<frame name="interact" src="interact.php?' . SID . '">
</frameset>


Jul 17 '05 #3

P: n/a
w = water on the map L= land and T = the town id

for some reason the else statement is what's getting pulled the
script is located at www.severedrealm.net/testing/index.php

Jul 17 '05 #4

P: n/a
On Sat, 03 Apr 2004 12:24:59 -0600, Josh Dismukes <sk*******@yahoo.com> wrote:
/// THE PROBLEM STARTS HERE AND IS SOMEWHERE BELOW!
IT'S SUPPOSED TO PULL THE MAP TYPE FOR THE DB, BUT IT'S PULLING THE
ELSE STATEMENT FOR EXAMPLE GO TO SEVEREDREALM.NET/TESTING //Query the Database
$query = "SELECT type FROM map WHERE map_file = " .
$_SESSION['new_map'] . " AND col = " . $_SESSION['new_col'] . " AND
row = " . $_SESSION['new_row'];
$result = mysql_query($query) or die ("Error in query: $query. " .
mysql_error());
$db_cell_type = mysql_fetch_array($result)
You haven't checked if you actually fetched a row, $db_cell_type could be
false.
//Evaluate the Cell Type
if ($db_cell_type['type']=='W'){


OK, you say it's something to do with it going to the else branch when you
weren't expecting it. If it's going to the else branch, this is false.
$_SESSION['new_col']=$_SESSION['old_col'];
$_SESSION['new_row']=$_SESSION['old_row'];
$_SESSION['new_map']=$_SESSION['old_map'];
$_SESSION['celltype']='W';}
elseif($db_cell_type['type']=='T'){
If it's going to the else branch, this is also false.

So put some debugging statements in the code before the 'if', to print out
what you're actually getting. This is the simplest method of debugging; if you
can't quite work out what's going on, put print statements all through the code
so show you the values.

var_dump() is a particularly useful function for dumping out variables as it
shows you the type of the variable, and will format arrays for you. You might
want to surround it with <pre></pre> tags to make it more readable for arrays.

If you haven't already, make sure error_reporting is set to E_ALL. PHP can
help you out if you ask for it, and it knows a lot more about the script than
random people off Usenet seeing your script for the first time without any
context or any idea what you have in your database.
$query2 = "SELECT townID FROM map WHERE map_file = " .
$_SESSION['new_map'] . " AND col = " . $_SESSION['new_col'] . " AND
row = " . $_SESSION['new_row'];
$db_result2 = @mysql_query($query2);
Don't ignore whether the query succeeded or not.
$db_townid = mysql_fetch_array($db_result2);
$_SESSION['townID'] = $db_townid;
$_SESSION['is_town'] = 1;
$_SESSION['celltype']='T';}
else {
$_SESSION['old_col']=$_SESSION['new_col'];
$_SESSION['old_row']=$_SESSION['new_row'];
$_SESSION['old_map']=$_SESSION['new_map'];
$_SESSION['celltype']='L';}

?>


--
Andy Hassall <an**@andyh.co.uk> / Space: disk usage analysis tool
http://www.andyh.co.uk / http://www.andyhsoftware.co.uk/space
Jul 17 '05 #5

P: n/a

"josh dismukes" <sk*******@yahoo.com> wrote in message
news:90**************************@posting.google.c om...
/// Were having serious problems with this script it's basically the
map script allowing player movement but the problem is in the QUERY
and if statements on the cell type. Any help will be much appreciated
thanks you <snip>
/// THE PROBLEM STARTS HERE AND IS SOMEWHERE BELOW!
//Query the Database
$query = "SELECT type FROM map WHERE map_file = " .
$_SESSION['new_map'] . " AND col = " . $_SESSION['new_col'] . " AND
row = " . $_SESSION['new_row'];
$result = mysql_query($query) or die ("Error in query: $query. " .
mysql_error());
$db_cell_type = mysql_fetch_array($result)

<snip>

Houston, we have an unidentifiable flying schema. Try die($query) after
construction and seeing if cut&pasting it into a phpMyAdmin SQL query
returns what you expected. Otherwise, you haven't left us much to work with.

Garp
Jul 17 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.