johncollins Posted November 2, 2009 Share Posted November 2, 2009 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"; } } ?> Link to comment https://forums.phpfreaks.com/topic/179953-if-statement-or-not-functioning-correctly/ Share on other sites More sharing options...
herghost Posted November 2, 2009 Share Posted November 2, 2009 Are you getting any error messages? If so what are they? whats it not doing? Link to comment https://forums.phpfreaks.com/topic/179953-if-statement-or-not-functioning-correctly/#findComment-949297 Share on other sites More sharing options...
cags Posted November 2, 2009 Share Posted November 2, 2009 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. Link to comment https://forums.phpfreaks.com/topic/179953-if-statement-or-not-functioning-correctly/#findComment-949302 Share on other sites More sharing options...
seanlim Posted November 2, 2009 Share Posted November 2, 2009 hehe.. i got excited for a moment there. thought i've been missing out on the awesome way to compare values Link to comment https://forums.phpfreaks.com/topic/179953-if-statement-or-not-functioning-correctly/#findComment-949310 Share on other sites More sharing options...
johncollins Posted November 2, 2009 Author Share Posted November 2, 2009 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 Link to comment https://forums.phpfreaks.com/topic/179953-if-statement-or-not-functioning-correctly/#findComment-949337 Share on other sites More sharing options...
johncollins Posted November 2, 2009 Author Share Posted November 2, 2009 it worked. but we all know that don't we Link to comment https://forums.phpfreaks.com/topic/179953-if-statement-or-not-functioning-correctly/#findComment-949340 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.