I'm a casual gamer and hobbyist programmer who knows a bit of Python. I'm trying to make a simple text adventure game engine, so I need to get raw input from the player.
This is Python 3.2.2, so my line is this:
var = input("What do you want to do? ").lower()
And that line works, but rather than typing that whole line I'd like to make it into a function (something like "getinput()"). From what I've read about input() and functions I'm looking for a function that doesn't return anything, but changes another variable's state (here "var") as a "side effect."
I do have a working function "halt()" that takes no arguments:
def halt():
input("(Press Enter to continue...) ")
print("")
Calling "halt()" gives the prompt, waits for Enter, then prints a blank line and moves on, which I intended.
The function I'm trying to get to work looks like this:
def getinput(x):
x = input("What do you want to do? ").lower()
print("")
After defining getinput(x):
var = ""
getinput(var)
print(var)
That snippet does not print the user's input, and I'm confused as to why. What do I need to do to make this work in the intended fashion?
Is what I'm trying to do impossible with a function, or is there just something I don't know about scope? Should I be at codereview?