473,699 Members | 2,734 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

/// 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.ph p";

//Register all the variables
if (!$_SESSION['new_map']) {session_regist er('new_map');
$_SESSION['new_map'] = 22;}
if (!$_SESSION['old_map']) {session_regist er('old_map');
$_SESSION['old_map'] = 22;}
if (!$_SESSION['new_col']) {session_regist er('new_col');
$_SESSION['new_col'] = 0;}
if (!$_SESSION['new_row']) {session_regist er('new_row');
$_SESSION['new_row'] = 0;}
if (!$_SESSION['old_col']) {session_regist er('old_col');
$_SESSION['old_col'] = 0;}
if (!$_SESSION['old_row']) {session_regist er('old_row');
$_SESSION['old_row'] = 0;}
if (!$_SESSION['cell_type']) {session_regist er('cell_type') ;
$_SESSION['cell_type'] = 'A';}
if (!$_SESSION['townid']) {session_regist er('townid');
$_SESSION['townid'] = 0;}
if (!$_SESSION['is_town']) {session_regist er('is_town');
$_SESSION['is_town'] = 0;}
if (!$_SESSION['townmap']) {session_regist er('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($qu ery) or die ("Error in query: $query. " .
mysql_error());
$db_cell_type = mysql_fetch_arr ay($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($q uery2);
$db_townid = mysql_fetch_arr ay($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.p hp?' . SID . '">
</frameset>
Jul 17 '05 #1
5 1772
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($qu ery) or die ("Error in query: $query. " .
mysql_error()) ;
$db_cell_type = mysql_fetch_arr ay($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($q uery2);
$db_townid = mysql_fetch_arr ay($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.p hp?' . 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
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_star t ();
require_once "connect.ph p";

//Register all the variables
if (!$_SESSION['new_map']) {session_regist er('new_map');
$_SESSION['new_map'] = 22;}
if (!$_SESSION['old_map']) {session_regist er('old_map');
$_SESSION['old_map'] = 22;}
if (!$_SESSION['new_col']) {session_regist er('new_col');
$_SESSION['new_col'] = 0;}
if (!$_SESSION['new_row']) {session_regist er('new_row');
$_SESSION['new_row'] = 0;}
if (!$_SESSION['old_col']) {session_regist er('old_col');
$_SESSION['old_col'] = 0;}
if (!$_SESSION['old_row']) {session_regist er('old_row');
$_SESSION['old_row'] = 0;}
if (!$_SESSION['cell_type']) {session_regist er('cell_type') ;
$_SESSION['cell_type'] = 'A';}
if (!$_SESSION['townid']) {session_regist er('townid');
$_SESSION['townid'] = 0;}
if (!$_SESSION['is_town']) {session_regist er('is_town');
$_SESSION['is_town'] = 0;}
if (!$_SESSION['townmap']) {session_regist er('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.NE T/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($qu ery) or die ("Error in query: $query. " .
mysql_error()) ;
$db_cell_type = mysql_fetch_arr ay($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($q uery2);
$db_townid = mysql_fetch_arr ay($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.p hp?' . SID . '">
</frameset>


Jul 17 '05 #3
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
On Sat, 03 Apr 2004 12:24:59 -0600, Josh Dismukes <sk*******@yaho o.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.NE T/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($qu ery) or die ("Error in query: $query. " .
mysql_error() );
$db_cell_type = mysql_fetch_arr ay($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($q uery2);
Don't ignore whether the query succeeded or not.
$db_townid = mysql_fetch_arr ay($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

"josh dismukes" <sk*******@yaho o.com> wrote in message
news:90******** *************** ***@posting.goo gle.com...
/// 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($qu ery) or die ("Error in query: $query. " .
mysql_error());
$db_cell_type = mysql_fetch_arr ay($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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
15280
by: FLOTServer | last post by:
Here's my problem: I run a gameserver that runs the game "Medal of Honor". On the game server is log file which contains all of the data from the players for that day (kills, deaths, etc...). I have a perl script that runs on my webserver, which is supposed to login to the gameserver and download the log. The problem is that when it gets to the part where it needs to download the file, it aborts. The gameserver FTP requires I use port 24...
0
2147
by: dnphamus13 | last post by:
I'm new to this and drowning right now. I would like to put my database online for viewing. I managed to do the filtering but i need to do PAGING as the XML doc get bigger. From what i understand this is what I need to do; transform the current XML doc with the filterring xsl, then somehow add the paging xsl. That's the part i'm having trouble with. I'm using JavaScript to apply the filterring XSL to XML doc. Filterring is based on what...
1
1866
by: Scythen | last post by:
I’m developing script system based on C# script for a game engine. Scripts are written in C# and compiled at run time by a C# class library. The native C++ game code accesses the script compiler class library through a COM interface. Compile scripts are passed back to the native C++ game code as COM interfaces as well. To run a script the game calls pScript->Run(pGameInterface). The pGameInterface is another COM object written in C# that...
1
9634
by: David Van D | last post by:
Hi there, A few weeks until I begin my journey towards a degree in Computer Science at Canterbury University in New Zealand, Anyway the course tutors are going to be teaching us JAVA wth bluej and I was wondering if anyone here would be able to give me some tips for young players such as myself, for learning the language. Is this the best Newsgroup for support with JAVA?
10
3830
by: Max Kubierschky | last post by:
Hello, I'm planning to give a game programming course for kids of mixed age. For this, I am looking for an open source 2D game development kit. I am also willing to participate in the development of the development kit. Features I'd like to see - Possibility to construct simple games via drag and drop without programming - Integration into an IDE - Based on Java or Python
3
1898
by: =?Utf-8?B?cGNnYW1lcg==?= | last post by:
Is VB good for game development? Or is C# or some other language better? I'm a beginner programmer and would like to get into game development. I can't find any decent tutorials, so links would be very helpful. Thanks
0
1470
by: Advertiser for `2D Games Development Central` | last post by:
New to game development? Need a headstart in creating that first game of yours? Want to meet others who share a passion for playing and creating games? Need support, but don't know where go for it? Are you just passionate about games? 2D Game Development Central is a newly founded group on Google Groups that is dedicated to the creation of games, especially with regards to 2D. We offer you the chance to join a community of newcomers just...
6
1807
by: pereges | last post by:
I want to begin by making simple 2D games for Dos. What particular features of C should I look to strengthen ? I am not asking about the graphics bit but in general.
7
2370
by: Benjamin Vigneaux | last post by:
Well, I'm very interested in game development, I'm just starting out though, browsing here and there for tutorials, references, etc.. and learning about the game development industry... What i've realized is that, apparently, most of the games out there are likely to be coded in C++, is this because the language offers features which are better suited for game development? or just because it has been out in market for a longer period of...
0
8612
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9032
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8880
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7743
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6532
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4373
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4625
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2342
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2008
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.