I am trying to have xpos and ypos change based on the direction the player enters. The program succeeds in asking Where to? but the position does not change. The script also always defaults to the last condition (puts("You're drunk.")).
For example:
> n
0
1
However, my output is:
> n
You're drunk.
0
0
This is my current code:
north = "n"
west = "w"
south = "s"
east = "e"
xpos = 0
ypos = 0
puts("WHERE TO?")
compass = gets
if compass == north
ypos = ypos + 1
elseif compass == west
xpos = xpos - 1
elseif compass == south
ypos = ypos - 1
elseif compass == east
xpos = xpos + 1
else
puts("You're drunk.") #if the player does not submit a proper direction
puts(xpos) #for debugging. prints zero when called showing the player has not moved
puts(ypos)
end
puts(...)here can becomeputs .... I've noticed that this seems to the the Ruby way to do things, though your code is still correct.chomp!your input.elsif, notelseif, at least as far as I know.