Text Doesnt Update

For discussions about game development that does not fit in any of the other topics.
Post Reply
Baseball435
Posts: 548
Joined: Sun May 30, 2010 3:49 am

Text Doesnt Update

Post by Baseball435 »

Hey everyone. I have a map system working and when the person presses on north, south, east, or west it moves them accordingly. What it does is when you press the button it goes to the scripting page and then redirects back to the main page. One of the parts I have is that it says "welcome to *map name* " but when i press the button everything seems to update except for that and it stays to whatever it said before the button was pressed. so the code for the text is:

Code: Select all

<center><h1><u>Welcome to 
	  <?php echo $playerinfo3['map'];?><br />
and then the code for the button pressed page (compass.php) is:

Code: Select all

<?php 
session_start();
include './config/connect.php';
include './config/session.php';

$username = $_SESSION['username'];

$playerinfo="SELECT * from users where username='$username'";
$playerinfo2=mysql_query($playerinfo) or die("Could not get user stats");
$playerinfo3=mysql_fetch_array($playerinfo2);
if($playerinfo3) {
if(isset($_SESSION['username'])) {
	
	if(isset($_POST['north'])) {
			$x = $playerinfo3['x'];
			$y = $playerinfo3['y'];
	
			$ny = $y + 1;
			$nx = $x + 0;
			
			mysql_query("UPDATE users SET x='$nx', y='$ny' WHERE username='$username'");
			
			$mapinfo="SELECT * from map where x='$x' and y='$y'";
			$mapinfo2=mysql_query($mapinfo) or die("Could not get map stats");
			$mapinfo3=mysql_fetch_array($mapinfo2);
	
			$playermap = $mapinfo3['map'];

			mysql_query("UPDATE users SET map='$playermap' WHERE username='$username'");
	} 
	elseif(isset($_POST['south'])) {
			$x = $playerinfo3['x'];
			$y = $playerinfo3['y'];
			
			$ny = $y - 1;
			$nx = $x + 0;
			
			mysql_query("UPDATE users SET x='$nx', y='$ny' WHERE `username`='$username'");
			
			$mapinfo="SELECT * from map where x='$x' and y='$y'";
			$mapinfo2=mysql_query($mapinfo) or die("Could not get map stats");
			$mapinfo3=mysql_fetch_array($mapinfo2);
	
			$playermap = $mapinfo3['map'];
			
			mysql_query("UPDATE users SET map='$playermap' WHERE username='$username'");
	} 
	elseif(isset($_POST['west'])) {
			
			$x = $playerinfo3['x'];
			$y = $playerinfo3['y'];
			
			$nx = $x - 1;
			$ny = $y + 0;
			
			mysql_query("UPDATE users SET x='$nx', y='$ny' WHERE username='$username'");	
			
			$mapinfo="SELECT * from map where x='$x' and y='$y'";
			$mapinfo2=mysql_query($mapinfo) or die("Could not get map stats");
			$mapinfo3=mysql_fetch_array($mapinfo2);
	
			$playermap = $mapinfo3['map'];
			
			mysql_query("UPDATE users SET map='$playermap' WHERE username='$username'");
	}
	elseif(isset($_POST['east'])) {
			
			$x = $playerinfo3['x'];
			$y = $playerinfo3['y'];
			
			$nx = $x + 1;
			$ny = $y + 0;
			
			mysql_query("UPDATE users SET x='$nx', y='$ny' WHERE username='$username'");	
			
			$mapinfo="SELECT * from map where x='$x' and y='$y'";
			$mapinfo2=mysql_query($mapinfo) or die("Could not get map stats");
			$mapinfo3=mysql_fetch_array($mapinfo2);
	
			$playermap = $mapinfo3['map'];
			
			mysql_query("UPDATE users SET map='$playermap' WHERE username='$username'");
	}
	header("Location:indext.php");
}
}
?>
Could someone please help me! :(
User avatar
Jackolantern
Posts: 10891
Joined: Wed Jul 01, 2009 11:00 pm

Re: Text Doesnt Update

Post by Jackolantern »

I'm having a hard time wrapping my head around the problem. When you click the directional link, it goes to a processing page that is supposed to say "Welcome to <current map name>", and you click it to go to that part of the map? What exactly is going wrong? Could you not combine the processing page and the map page into the same script so you can simply reload the same page, and skip the processing page all together?
The indelible lord of tl;dr
Baseball435
Posts: 548
Joined: Sun May 30, 2010 3:49 am

Re: Text Doesnt Update

Post by Baseball435 »

Well what I have is the main page has the 4 buttons on it and it also has where it says welcome to "map name" and when you click on one of the buttons it goes to compass.php, updates your x and y coordinates and then goes back to the main page but the welcome part on the MAIN PAGE doesn't update the mapname. The reason im not putting it on the same page is because If it someone reloads the page again it will think the button is being pressed
User avatar
Jackolantern
Posts: 10891
Joined: Wed Jul 01, 2009 11:00 pm

Re: Text Doesnt Update

Post by Jackolantern »

Well, I did have a solution to the refresh-moving, as outlined in your other thread ;) You would save a whole page load by making it on the same page.

As far as the issue on the main page, your actual line of code looks sound to me. Are you sure you are not setting the $playerinfo3 variable on the compass page and then trying to use the value on the main page page, because I see it being set on compass.php, which I am assuming is different than the actual map page? That value is lost when you go forward to the map page.

If that is not the issue, and you are re-initializing the $playerinfo3 variable on the map page, if you could post the full map page I will take a look at it.
The indelible lord of tl;dr
Baseball435
Posts: 548
Joined: Sun May 30, 2010 3:49 am

Re: Text Doesnt Update

Post by Baseball435 »

Ok will do tomorrow, I'm going to bed. Please excuse my messiness in the code, I kinda threw it together while I hardly knew anything about php and HTML :P
User avatar
Jackolantern
Posts: 10891
Joined: Wed Jul 01, 2009 11:00 pm

Re: Text Doesnt Update

Post by Jackolantern »

Really, your code is not bad. The most important thing, though, is to comment, comment, comment if you are not doing that in your more current scripts. Once your scripts stop being self-documenting (when they become more complex, which they will), you are pretty much guaranteeing that you will have no idea what is going on in your scripts after just a month or so. I was saved by my own comments in that script I posted for you in your other thread relating to the map situation. I would have no idea what I was doing or where I was doing it if not for those comments.
The indelible lord of tl;dr
User avatar
Callan S.
Posts: 2042
Joined: Sun Jan 24, 2010 5:43 am

Re: Text Doesnt Update

Post by Callan S. »

It's funny how quickly you can forget the intent of code you typed? It's just not the sort of stuff that goes to long term memory. My commenting is starting to look like story telling "And now the nasty raptor has a chance to hit", lol!
Fight Cycle : My latest Browser game WIP
Driftwurld : My Browser Game WIP
Philosopher Gamer : My Blog
User avatar
Jackolantern
Posts: 10891
Joined: Wed Jul 01, 2009 11:00 pm

Re: Text Doesnt Update

Post by Jackolantern »

Exactly, and no matter how good your programming skills, programming is just incompatible to the human brain. Therefore, we quickly forget what we were doing. It is like doing a huge calculus problem, and then a month later looking at only one line of it and trying to remember why you were doing it. Hyper-logical things such as math and programming just don't mesh well with the creativity-based human brain. So that is why we have to write comments and write them as we are coding because the brain loses the intent so, so fast.
The indelible lord of tl;dr
Baseball435
Posts: 548
Joined: Sun May 30, 2010 3:49 am

Re: Text Doesnt Update

Post by Baseball435 »

yeah i actually am starting to make scripts in ones that are complex like my craft item script which is 549 lines of raw code. (took forever). but here is my main code where everything goes on and where i am having my problem.

Code: Select all

<?php
	session_start();
include './config/connect.php';
include './config/session.php';
	
	$playerinfo="SELECT * from users where username='$username'";
	$playerinfo2=mysql_query($playerinfo) or die("Could not get user stats");
	$playerinfo3=mysql_fetch_array($playerinfo2);
	
	$x = $playerinfo3['x'];
	$y = $playerinfo3['y'];
	
	$mapinfo="SELECT * from map where x='$x' and y='$y'";
	$mapinfo2=mysql_query($mapinfo) or die("Could not get map stats");
	$mapinfo3=mysql_fetch_array($mapinfo2);
	
	$playermap = $mapinfo3['map'];
	$mapmonster = $mapinfo3['Monster'];

	mysql_query("UPDATE users SET map='$playermap' WHERE username='$username'");

	$monsterinfo="SELECT * from monsters where name='$mapmonster'";
	$monsterinfo2=mysql_query($monsterinfo) or die("Could not find the monster!");
	$monsterinfo3=mysql_fetch_array($monsterinfo2);
	
	$shopsinfo="SELECT * from shops where map='$playermap'";
	$shopsinfo2=mysql_query($shopsinfo) or die("Could not find the monster!");
	//$shopsinfo3=mysql_fetch_array($shopsinfo2);
	
	$monstername = $monsterinfo3['name'];
	
	$houseinfo="SELECT * from housing where map='$playermap' LIMIT 3";
	$houseinfo2=mysql_query($houseinfo) or die("Could not get map statss");
	//$houseinfo4=mysql_fetch_array($houseinfo2);
	
	$rand = rand(1000000, 2000000);
?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<LINK REL=StyleSheet HREF="style.css" TYPE="text/css" MEDIA=screen>
<head>
<title>Welcome to <?php echo $playerinfo3['map'];?></title>
</head>
<body alink="#00FF00" vlink="#00FF00" link="#00FF00">

   <div id="container1">
///////////////////////right side bar/////////////////////////////
      <div id="one2"><center><p><h3><strong><u>Stats</u></strong></h3>
      User: <?php echo $playerinfo3['username'];?> <br /><br />Health: <?php echo $playerinfo3['hp']; ?><br /> <br /> Level: <?php echo $playerinfo3['level'];?><br /><br /> Gold: <?php echo $playerinfo3['money'];?><br /> <br /> Strength: <?php echo $playerinfo3['strength'];?><br /><br /> Defence: <?php echo $playerinfo3['defence'];?><br /><br /> Sneak: <?php echo $playerinfo3['sneak'];?><br /><br /> Agility: <?php echo $playerinfo3['agility'];?><br /><br /> Lockpicking: <?php echo $playerinfo3['lockpicking'];?></p><br /><p4><a href="craftitem.php">Craft Items</a><br /><a href="inventory.php">Inventory</a> <br /><a href='logout.php'>Log Out</a><br /><br /></p4></center></div>
//////////////////end of side bar/////////////////////////////////
      <div id="main1"><center><h1><u>Welcome To 
	  <?php echo $playerinfo3['map'];?><br /><br /></h1></u>
      		<p>
            <?php 
			while($shopsinfo3=mysql_fetch_array($shopsinfo2)) {
			$url = $shopsinfo3['url'];
			$shopname = $shopsinfo3['name'];
			?>
            <a href="<?php echo $url; ?>"><? echo $shopname; ?></a>
            <?php
			}
			?><br />
      		<a href="wood.php?map=<?php echo $playerinfo3['map'];?>">Chop Some Lumber</a><br />
            <a href="rock.php?map=<?php echo $playerinfo3['map'];?>">Mine Some Rocks</a><br />
            <a href="iron.php?map=<?php echo $playerinfo3['map'];?>">Go To The Iron Mine</a><br />
            <a href="crops.php?map=<?php echo $playerinfo3['map'];?>">Collect Crops</a><br /><br /></p>
            <p1><u>Player Owned Shops And Houses:</p1></u><br /><br /></p1>
      
      	<p>
//////////////////////houses and shops//////////////////////////
      	<a href="buyhouse.php">House Manager</a><br /><br />
      		<?php 
	  		while($houseinfo3=mysql_fetch_array($houseinfo2)) { 
	  			$houseeid = $houseinfo3['id'];?>
      			<a href="playerhouse.php?houseeid=<?php echo $houseeid; $_SESSION['houseid']=$houseeid;?>"><?php echo $houseinfo3['name']; ?><br /></a></p>
      <?php	  
	   } ?></p1><a href="allhs.php">All Houses And Shops...</a></center><br />
            
      		</center>
       </div>     
      <div id="two2"><br />
      /////////////////////main compass///////////////////////////
      		<div id="compass">
      			<form method="post" action="compass.php">
        			<div id="ncompass"><input type="submit" value="North" name="north" align="middle"></div><br />
						<div id="ewcompass"><input type="submit" value="West" name="west" align="right">
        				<input type="submit" value="East" name="east" align="left"></div><br />
        						<div id="scompass"><input type="submit" value="South" name="south" align="middle"></div><br />
        </form>
      		</div>
////////////////////end of compass//////////////////////
      //players online
      <br /><br /><center><p1><a href="playersonline.php">Players At This Location</a></u><br /><br /><br /><br /></h1>
      //resources
      <h3>
      Lumber: <?php echo $playerinfo3['lumber']; ?><br />
      Rock: <?php echo $playerinfo3['rock']; ?><br />
      Iron: <?php echo $playerinfo3['iron']; ?><br />
      Crops: <?php echo $playerinfo3['crops']; ?><br /><br /> <br />
      </h3>
	  //check if monster
	  <?php if($mapinfo3['Monster'] == "") { ?>
            <p3><br />No monsters are in this area</p3>
            <?php } else { ?>
           	
<center><br /></u><p3>A <?php echo $monstername; ?> has entered this area and is lurking on <?php echo $playermap; ?><br /><br /><a href="attack.php?name=<?php echo $monstername;?>">Attack the <?php echo $monstername?>?</a></p3></center><br />
            <?php } ?>
   </div>

</body>
</html>
User avatar
Jackolantern
Posts: 10891
Joined: Wed Jul 01, 2009 11:00 pm

Re: Text Doesnt Update

Post by Jackolantern »

You have basically the same statement a bit lower down the page on several different links ("rock.php", "wood.php", etc.). Does it work there? Does the playerinfo3 array work as expected in other places in the page, and you're sure that is the correct column name in the database? Also, do you have PHP set to show errors? If you don't, then error'd out statements simply are ignored, or have strange effects.

Sometimes I have had very odd issues with using an associative array in an echo with no text. Sometimes it fixes it to remove the single-quotes around the offset ('map'). There is some rule in PHP that dictates this, but I can't remember the specifics. But then sometimes I simply assign the value of the array to a simple variable, and echo that.
The indelible lord of tl;dr
Post Reply

Return to “General Development”