Zayl Posted January 31, 2007 Share Posted January 31, 2007 I am having a problem with line 41 in this code and i cant figure out why. It should work according to other people. <?php $World = simplexml_load_file("gameworld.xml"); $CurrentPos = 0; $Done = 0; print "\n"; printplace() ; function printplace() { GLOBAL $World, $CurrentPos; $Room = $World->ROOM[$CurrentPos]; $Name = $Room->NAME; $Desc = wordwrap((string)$Room->DESC); print "$Name\n"; print str_repeat('-', strlen($Name)); print "\n$Desc\n\n"; if ((string)$Room->NORTH != '-') { $index = (int)$Room->NORTH; print "North: {$World->ROOM[$index]->NAME}\n"; } if ((string)$Room->SOUTH != '-') { $index = (int)$Room->SOUTH; print "South: {$World->ROOM[$index]->NAME}\n"; } if ((string)$World->ROOM[$CurrentPos]->WEST != '-') { $index = (int)$Room->WEST; print "West: {$World->ROOM[$index]->NAME}\n"; } if ((string)$World->ROOM[$CurrentPos]->EAST != '-') { $index = (int)$Room->EAST; print "East: {$World->ROOM[$index]->NAME}\n"; } print "\n"; } while (!$Done) { $input = fgets(STDIN); print "\n"; // add another line break after the user input $input = split(' ', $input); switch(trim($input[0])) { case 'north': if ((string)$World->ROOM[$CurrentPos]->NORTH != '-') { $CurrentPos = (int)$World->ROOM[$CurrentPos]->NORTH; printplace() ; } else { print "You cannot go north!\n"; } break; case 'south': if ((string)$World->ROOM[$CurrentPos]->SOUTH != '-') { $CurrentPos = (int)$World->ROOM[$CurrentPos]->SOUTH; printplace() ; } else { print "You cannot go south!\n"; } break; case 'west': if ((string)$World->ROOM[$CurrentPos]->WEST != '-') { $CurrentPos = (int)$World->ROOM[$CurrentPos]->WEST; printplace() ; } else { print "You cannot go west!\n"; } break; case 'east': if ((string)$World->ROOM[$CurrentPos]->EAST != '-') { $CurrentPos = (int)$World->ROOM[$CurrentPos]->EAST; printplace() ; } else { print "You cannot go east!\n"; } break; case 'look': printplace() ; break; case 'quit': $Done = 1; break; } } print "\nThanks for playing!\n\n"; ?> if you can please im open for ideas for a fix or for a reason why its not working. Link to comment https://forums.phpfreaks.com/topic/36511-help-with-a-line-of-code-please/ Share on other sites More sharing options...
Jessica Posted January 31, 2007 Share Posted January 31, 2007 STDIN is not a resource handle. Read the manual on how to use this function http://us2.php.net/fgets Link to comment https://forums.phpfreaks.com/topic/36511-help-with-a-line-of-code-please/#findComment-173838 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.