dodle
September 19th, 2008, 08:09 AM
Edit: Here are the scripts that will describe my problem better:
# This script is called "name"
def char_name():
loop = "1"
while loop == "1":
print
char_name = raw_input('Please select a name for the main character.\
\nAolis is the default: ')
if char_name == "":
char_name = "Aolis"
print
confirm = raw_input('You have chosen the name "%s", is this okay? ' % (char_name)) # Confirm that this is the desired name
if confirm in ("yes", "y", "Yes", "Y"):
loop = "0"
elif confirm not in ("yes", "y", "Yes", "Y"):
loop = "1"
return char_name
def char_gender():
loop = "1"
while loop == "1":
print
char_gender = raw_input('Is %s a male or a female? ' % char_name())
if char_gender in ("f", "F", "female", "Female", "g", "G", "girl", "Girl"):
char_gender = "female"
print "%s is a %s." % (char_name(), char_gender)
loop = "0"
if char_gender in ("m", "M", "male", "Male", "b", "B", "boy", "Boy"):
char_gender = "male"
print "%s is a %s" % (char_name(), char_gender)
loop = "0"
return char_gender
# Trial of Aolis v0.1 2008
import name
print
print "Trial of Aolis v0.1 2008"
print
raw_input('press "enter" to start')
game_state = "active"
while game_state == "active":
char_name = name.char_name()
char_gender = name.char_gender()
# Here, the main game starts
print
print "%s, %s" % (char_name, char_gender)
print
# Main game ends here
cont_ = "undecided"
while cont_ == "undecided":
game_over = raw_input('Would you like to play again?')
if game_over in ("yes", "y", "Yes", "Y"):
game_state = "active"
cont_ = "decided"
elif game_over in ("no", "n", "No", "N"):
game_state = "inactive"
cont_ = "decided"
elif game_over in ("name", "Name"):
print
print char_name
print
cont_ = "undecided"
elif game_over not in ("yes", "y", "Yes", "Y", "no", "n", "No", "N", "name", "Name"):
print
print 'I don\'t understand "%s".' % (game_over)
print
cont_ = "undecided"
print
raw_input('Press "enter" to exit')
char_name() is being called three times. But if I change the following lines from "name":
char_gender = raw_input('Is %s a male or a female? ' % char_name())
print "%s is a %s." % (char_name(), char_gender)
print "%s is a %s" % (char_name(), char_gender)
to:
char_gender = raw_input('Is %s a male or a female? ' % char_name)print "%s is a %s." % (char_name, char_gender)print "%s is a %s" % (char_name, char_gender)
Then char_name isn't called multiple times but the output looks like this:
<function char_name at 0x009FE070>
Edit: I have been able to solve this problem by defining all of my functions in the main script instead of importing, but I want to get better at importing. So, if possible I would like to keep the two scripts separate.
# This script is called "name"
def char_name():
loop = "1"
while loop == "1":
char_name = raw_input('Please select a name for the main character.\
\nAolis is the default: ')
if char_name == "":
char_name = "Aolis"
confirm = raw_input('You have chosen the name "%s", is this okay? ' % (char_name)) # Confirm that this is the desired name
if confirm in ("yes", "y", "Yes", "Y"):
loop = "0"
elif confirm not in ("yes", "y", "Yes", "Y"):
loop = "1"
return char_name
def char_gender():
loop = "1"
while loop == "1":
char_gender = raw_input('Is %s a male or a female? ' % char_name())
if char_gender in ("f", "F", "female", "Female", "g", "G", "girl", "Girl"):
char_gender = "female"
print "%s is a %s." % (char_name(), char_gender)
loop = "0"
if char_gender in ("m", "M", "male", "Male", "b", "B", "boy", "Boy"):
char_gender = "male"
print "%s is a %s" % (char_name(), char_gender)
loop = "0"
return char_gender
# Trial of Aolis v0.1 2008
import name
print "Trial of Aolis v0.1 2008"
raw_input('press "enter" to start')
game_state = "active"
while game_state == "active":
char_name = name.char_name()
char_gender = name.char_gender()
# Here, the main game starts
print "%s, %s" % (char_name, char_gender)
# Main game ends here
cont_ = "undecided"
while cont_ == "undecided":
game_over = raw_input('Would you like to play again?')
if game_over in ("yes", "y", "Yes", "Y"):
game_state = "active"
cont_ = "decided"
elif game_over in ("no", "n", "No", "N"):
game_state = "inactive"
cont_ = "decided"
elif game_over in ("name", "Name"):
print char_name
cont_ = "undecided"
elif game_over not in ("yes", "y", "Yes", "Y", "no", "n", "No", "N", "name", "Name"):
print 'I don\'t understand "%s".' % (game_over)
cont_ = "undecided"
raw_input('Press "enter" to exit')
char_name() is being called three times. But if I change the following lines from "name":
char_gender = raw_input('Is %s a male or a female? ' % char_name())
print "%s is a %s." % (char_name(), char_gender)
print "%s is a %s" % (char_name(), char_gender)
to:
char_gender = raw_input('Is %s a male or a female? ' % char_name)print "%s is a %s." % (char_name, char_gender)print "%s is a %s" % (char_name, char_gender)
Then char_name isn't called multiple times but the output looks like this:
<function char_name at 0x009FE070>
Edit: I have been able to solve this problem by defining all of my functions in the main script instead of importing, but I want to get better at importing. So, if possible I would like to keep the two scripts separate.