473,394 Members | 1,785 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

question about function not executing

Hello all,

I hope I am posting this correctly. I am running Python 2.4.2 on
Slackware 11.0 using IDLE. I am in the process of learning python so I
am writing a text adventure game using functions and global variables
only. I know there is a better way to do this but that is for later.

When I run the python program it works fine until I try to go west
from my inital start room. I get the room description but no raw_input
prompt. I just get dumped back to >>in the python shell. I think I
am missing something simple. I pasted in the code below. I am using
gmail so I hope the formatting stays. If not I can send the .py as an
attachment if needed. Thanks.

Ara

Code:
#A sample text adventure game
#Version 0.1
#By Ara Kooser
#Using global variables for the character
#Want to use a function instead

stre = 9
con = 8
inte = 11
agl = 14
app = 10
mag = 6
sz = 9

hp = 17

reputation = 0

stealth = False

quest1 = False
quest2 = False

curse = False
poison = False
diseased = False

ducats = 50
lira = 25
florin = 80
equipment = {'Sword': 1, 'Dagger': 1, 'Walking staff': 1, 'Leather Armor':1}
backpack = {'Flint and steel': 1, 'Rations': 7, 'dressing kit': 6,
'waterskin': 2}
belt_pouch = {}

################################################## ###################################

day = False
# help function that will give you a list of commands
def help():
print "look, examine (object), n, w, e, s, take (item)"
print "climb, stealth, fishing, herbalism, forage, haggle"
print "field dressing"
print "wield (object), attack, flee, close, withdraw"
print "backpack, belt pouch, cs"
print "Example: examine book, take ducats, attack orc"

# I want to setup the character has a function but I am not sure how
# to call and modify, the stats, counters, and flags. Currently I am
# setting these as global variables

#def character(self):
# #Initalize stats
# self.str = 9
# self.con = 8
# self.int = 11
# self.agl = 14
# self.app = 10
# self.mag = 6
# self.sz = 9

# self.hp = 17

# #Initalize flags
# self.quest1 = False
# self.quest2 = False

# self.curse = False
# self.poison = False
# self.diseased = False

#Initalize counters
# self.ducats = 50
# self.lira = 25
# self.florin = 80
# self.reputation = 0
# Sets up a character sheet to print out to screen
#To do list - make the sheet update as the game progresses
def character_sheet():
print """\
================================================== ==========================
Name: Profession:
Social Class: Race:

================================================== ==========================
Strength
Constitution
Intelligence
Agility
Appearance
Magic
Size
================================================== ==========================
Ducats: Lira: Florin:

Skills: Forage, Haggle, Stealth, Fishing, Herbalism, Climb, Sword, Staff,
Dagger, Field Dressing

Equipment: Backpack, Belt Pouch, Run of the Mill Sword, Dagger, Flint&Steel
1 week food, 2 waterskins, walking stick, dressing kit
================================================== ==========================
"""

def start():
print '''
SAMPLE TEXT ADVENTURE V0.1
You are the last person to leave the small village of Hommlet. The wooden
gate closes behind you and twilight reaches across the land. A dense mist
creeps up out of the ground, only to be kept at bay by the watchmens torches.
Somewhere deep in the woods lies the foul orcs you have tracked for several
days.

'''

print

def outside1():
global hp
global reputation
print " Current Hit Points = ",hp
print " Current Reputation = ",reputation
print ''' You are outside the town gates. The dirt road heads
(N)orth to another
town several days away. The forest lies (E)ast and (W)est through the
meadows. The
rumors you heard in town describe the orcs as being to the west. The town's gate
is to the (S)outh but it is locked for the night.
Type 'help' for a full list of commands.'''
print
prompt_out1()

def out1_desc():
print ''' The fog is growing denser as the sun sets on the meadows.
The exits are (N)orth, (E)ast and (W)est.'''
print
prompt_out1()

def prompt_out1():
global day
prompt_o1 = raw_input("Type a command: ").lower()
try:

if prompt_o1 == "help":
help()
print
prompt_out1()

elif prompt_o1 == "cs":
character_sheet()
print
prompt_out1()

elif prompt_o1 == "status":
print " Current Hit Points = ",hp
print " Current Reputation = ",reputation
prompt_out1()

elif prompt_o1 == "backpack":
print backpack
prompt_out1()

elif prompt_o1 == "belt pouch":
print belt_pouch
prompt_out1()

elif prompt_o1 == "equipment":
print equipment
prompt_out1()

################################################## ######################################
elif prompt_o1 == "examine fog":
print "The fog seems natural enough for this time of year."
print
prompt_out1()

elif prompt_o1 == "examine road":
print ''' The road is a well travelled dirt road
winding many leagues'''
print
prompt_out1()

elif prompt_o1 == "look":
out1_desc()

################################################## #####################################
elif prompt_o1 == "w":
meadow1()

elif prompt_o1 == "e":
meadow2()
elif prompt_o1 == "s":
#if day = False
print "The town's gate is closed for the night"
print
prompt_out1()
#elif
# town_1

elif prompt_o1 == "n":
n_road()

################################################## ####################################
elif prompt_o1 == "haggle":
print "There is no one to haggle with here."
promt_out1()

elif prompt_o1 == "stealth":
print "You try and be stealthy"
prompt_out1()

else:
print "Please choose another command. That command is invalid"
print
prompt_out1()

except ValueError:
print "Please choose another command. That command is invalid"
print
prompt_out1()
def meadow1():
global hp
global reputation
print " Current Hit Points = ",hp
print " Current Reputation = ",reputation
print ''' You are in the meadows that surrond the northwest of
the town. In the day the
field is a golden brown. Right now the grass is waist high and thickly
covered with dew. Your
footsteps and the sounds of the night are dampened here.
A broken trail leads into the forest (W)est. The meadow continues
(N)orth along the road.
(E)ast takes you back to the road and the entrance to Hommlet. The
wooden wall of the town is
just south of here. Type 'help' for a full list of commands.'''
print
prompt_meadow1

def meadow1_desc():
print ''' The fog bends the grass down and drops of water roll
off the blades. You can see
about 5 paces in front of you. Your clothes are starting to get damp.
The broken trail heads (W)est.
The road is (E)ast. The meadow continues (N)orth and the town's wall
is to the south.'''
prompt_meadow1

def prompt_meadow1():

prompt_m1 = raw_input("Type a command: ").lower()
try:

if prompt_m1 == "help":
help()
print
prompt_meadow1()

elif prompt_m1 == "cs":
character_sheet()
print
prompt_meadow1()

elif prompt_m1 == "status":
print " Current Hit Points = ",hp
print " Current Reputation = ",reputation

elif prompt_m1 == "backpack":
print backpack
prompt_meadow1()

elif prompt_m1 == "belt pouch":
print belt_pouch
prompt_meadow1()

elif prompt_m1 == "equipment":
print equipment
prompt_meadow1()

################################################## #############################################

elif prompt_m1 == "examine fog":
print "The fog seems natural enough for this time of year."
print
prompt_meadow1()

elif prompt_m1 == "examine grass":
print '''The grass would be a golden brown in the light
however now it's just
gray and damp.'''
print
prompt_meadow1()

elif prompt_m1 == "look":
meadow1_desc()

################################################## #############################################

elif prompt_m1 == "s":
#if day = False
print "The town's wooden wall is in your way"
print
prompt_meadow1()
#elif
# town_1

elif prompt_m1 == "w":
edge_forest1()

elif prompt_m1 == "e":
outside_1()

elif prompt_m1 == "n":
n_meadow_1()

################################################## ##############################################

elif prompt_m1 == "haggle":
print "There is no one to haggle with here."
promt_meadow1()

elif prompt_m1 == "stealth":
print "You try and be stealthy"
prompt_meadow1()

elif prompt_m1 == "forage":
if getGrass_m1 == 0:
print "You find some blades of grass and gather them up."
backpack['mdw_grass']
backpack['mdw_grass'] = 1
print backpack
getGrass == 1
prompt_meadow1()
elif getGrass_m1 == 1:
print "Someone has gathered the grass already."
print
prompt_meadow1()
else:
print "Please choose another command. That command is invalid"
print
prompt_meadow1()

except ValueError:
print "Please choose another command. That command is invalid"
print
prompt_meadow1()
start()
outside1()
--
Quis hic locus, quae regio, quae mundi plaga. Ubi sum. Sub ortu solis
an sub cardine glacialis ursae.
Nov 26 '06 #1
3 1664
Hint:

Posting only the piece of code causing the problem will give you more
answers...

Ara Kooser wrote:
Hello all,

I hope I am posting this correctly. I am running Python 2.4.2 on
Slackware 11.0 using IDLE. I am in the process of learning python so I
am writing a text adventure game using functions and global variables
only. I know there is a better way to do this but that is for later.

When I run the python program it works fine until I try to go west
from my inital start room. I get the room description but no raw_input
prompt. I just get dumped back to >>in the python shell. I think I
am missing something simple. I pasted in the code below. I am using
gmail so I hope the formatting stays. If not I can send the .py as an
attachment if needed. Thanks.

Ara
<clip>

Giving the command 'w', you call meadow1()
elif prompt_o1 == "w":
meadow1()
def meadow1():
<clip>
print
prompt_meadow1
So you end up here, the meadow1() function returns to the
except ValueError:
and ends then as expected.
>
def meadow1_desc():
prompt_meadow1
Same problem would occur in here.

I guess you want to call this:
def prompt_meadow1():

prompt_m1 = raw_input("Type a command: ").lower()
So write
prompt_meadow1()
instead of
prompt_meadow1

(experiment in python shell and you see the difference.
>>raw_input
<built-in function raw_input>
>>raw_input()
now python waits for your input

For the player, create a class.

class player(object):

def __init__(self):
self.poisoned = False

def take_poison(self):
print 'You are poisoned'
self.poisoned = True
# effects of poison in here:
# take some hitpoints
# maybe reduce some stats
# and so on...

# now, generate a player instance
p = player() # calls __init__
# poison the player
p.take_poison()

--
Juho Schultz

Nov 26 '06 #2
Ara Kooser wrote:
<snip>
When I run the python program it works fine until I try to go west
from my inital start room. I get the room description but no raw_input
prompt. I just get dumped back to >>in the python shell. I think I
am missing something simple. I pasted in the code below. I am using
<snip>

You've got at least 2 places that read
prompt_meadow1
instead of
prompt_meadow1()
like they should.

Cheers,
Jussi
Nov 26 '06 #3
Ara Kooser wrote:
<snip>
When I run the python program it works fine until I try to go west
from my inital start room. I get the room description but no raw_input
prompt. I just get dumped back to >>in the python shell. I think I
am missing something simple. I pasted in the code below. I am using
<snip>

You've got at least 2 places that read
prompt_meadow1
instead of
prompt_meadow1()
like they should.

Cheers,
Jussi

Nov 26 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: hpoliset | last post by:
I have a debugging question w.r.t core dumps with signal 4 Illegal instruction messages. I analyzed the core file through gdb. In simple english following is the pattern observed: I have an...
2
by: Silent Ocean | last post by:
Hi All I have following questions regarding C# Assembly and Threading. Let me know the precise answer or lead me to the proper materials. 1. Is memory leakeage possible in .Net Manager...
6
by: Bill Jones | last post by:
I'm trying to use this.RegisterStartupScript to add some javascript to and aspx page that will run when the page is loaded. Does anyone know if this function only works in the Page_Load function? ...
21
by: yeti349 | last post by:
Hi, I'm using the following code to retrieve data from an xml file and populate a javascript array. The data is then displayed in html table form. I would like to then be able to sort by each...
15
by: Sam Kong | last post by:
Hello! I got recently intrigued with JavaScript's prototype-based object-orientation. However, I still don't understand the mechanism clearly. What's the difference between the following...
7
by: bravesplace | last post by:
Hello, I am using the folling funtion to round a number to a single digit on my form: function round1(num) { return Math.round(num*1)/1 }
6
by: GarrettD78 | last post by:
Accidently posted this to the wrong group so I am reposting. This is probably a newbie question but I am a little confused about how to go next with my code. I think I want to use a factory pattern...
2
by: Ben Edwards (lists) | last post by:
I am using python 2.4 on Ubuntu dapper, I am working through Dive into Python. There are a couple of inconsictencies. Firstly sys.setdefaultencoding('iso−8859−1') does not work,I have to...
5
by: reycri | last post by:
Hi, I need to be able to do this: var func = new Function("var me = <selfRef>; alert(me.params);"); func.params = "This is a test parameter"; window.setTimeout(func, 500); Basically, I...
7
by: VK | last post by:
I was getting this effect N times but each time I was in rush to just make it work, and later I coudn't recall anymore what was the original state I was working around. This time I nailed the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.