Jump to content

if statement - or not functioning correctly


johncollins

Recommended Posts

hiya guys im having a few problems with an if statement and wondering if anyone could help me out.

 

im trying to identify wether or not a command is equal to "whater it is equal to" and also if it is equal to a series of numbers

 

basically im making an adventure game and in order to move around i must take into account walls and areas i cannot move too.

 

so here is the code. If you need any other pieces then just ask and il post.

 

its a bit rough but il clean it up when it works ;)

 

<?PHP

Function move($perameter, $dir){

$location = $_SESSION['location'];

$wi = $location + $perameter;

if ($wi === 5 || 9 || 13 || 17 || 21 && $dir === 'west'){

echo "You hit a wall while travelling " . $dir;

}

elseif ($wi < 1){

echo "unable to move to that location ";

echo $location . " under 1 ";

}

elseif ($wi > 24){

echo "unable to move to that location ";

echo $location . " over 24 ";

}

elseif($wi < 24 && $wi > 1){

$_SESSION['location'] = $_SESSION['location'] + $perameter;

room($_SESSION['location']);

}

else{

echo "what the ??? something is wrong";

}

}

?>

if ($wi === 5 || 9 || 13 || 17 || 21

 

PHP cannot compare values like that. I assume the objective is to check if $wi is equal to one of those values? You would either have to use...

 

$wi === 5 || $wi === 9 || $wi === 13 || $wi === 17 || $wi === 21 

 

...or...

 

$vals = array(5, 9, 13, 17, 21);

if(in_array($wi, $vals)) {

 

...or some other method.

that makes sense. in fact i feel a little silly. thanks for the speedy replies! :)

 

il just check if it works now.

 

O and im not getting any error messages, instead im getting the result of the statement even if its false. tis a pain tbh

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.