Jump to content

Debugging Help (Movement Generator)


Q695

Recommended Posts

For some reason X, and Y are being rewritten (only option 1 is showing up but the other stuff is visible) when they're intrtnal to the function (subtracting 1).

<?php
function mapgen($x, $y){
global $con, $cx, $cy, $cz, $m_q, $m_w, $m_e, $m_a, $m_s, $m_d, $m_z, $m_x, $m_c;
$mx=$cx+$x;
$my=$cy+$y;

echo $x.",". $y;

$sql_m= "select * from map WHERE x=$mx AND y=$my AND z=$cz";
$result = mysql_query($sql_m, $con) or die ("can not generate result " . mysql_error());
$row_m = mysql_fetch_assoc($result);
//print_r($row_m);
//echo $mx . "," . $my;
if ($row_m)
{
echo "<img src='images/" . $row_m['img'] . "' alt='terain' height='20' width='20' />";

if ($x='-1' && $y='1')
{$m_q=1;}
else if($x='0' && $y='1')
{$m_w=1;}
else if($x='1' && $y='1')
{$m_e=1;}
else if($x='-1' && $y='0')
{$m_a=1;}
else if($x='0' && $y='0')
{$m_s=1;}
else if($x='1' && $y='0')
{$m_d=1;}
else if($x='-1' && $y='-1')
{$m_z=1;}
else if($x='0' && $y='-1')
{$m_x=1;}
else if($x='1' && $y='-1')
{$m_c=1;}
else
{
echo"error";
}

}
else
{
echo "<img src='images/clear.gif' height='20' width='20' alt='null'>";
}

}
?>

Link to comment
https://forums.phpfreaks.com/topic/268788-debugging-help-movement-generator/
Share on other sites

  On 9/25/2012 at 5:36 PM, Q695 said:

if ($x='-1' && $y='1')

 

= is an assignment, meaning you are assigning '-1' to $x and '1' to $y. If you want to test the value of $x against '-1' to see if they are equal, you need to use == (two equal signs)

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.