473,666 Members | 2,065 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 = ",reputatio n
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 = ",reputatio n
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 = ",reputatio n
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 = ",reputatio n

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 1678
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(sel f):
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
17544
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 program with a piece of code -lets call it function1() that gets called by different callers. This function is executed 1000 's of times as while the binary is run and it works fine.
2
1206
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 Code ? 2. Is memory leakage possible in .Net Unmanaged Code ? 3. How can I find the what % of memory is being used by DLL at run time ? 4. What is difference between Sunchronous processing and Async
6
1982
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? Or can I put it anywhere. Right now it is inside the eventhandler function that is called on the "CheckChanged" event of a checkbox, but it never seems to add the javascript code to the page. Is there another way to do this? Let me explain the...
21
3198
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 column. Once the array elements are split, what is the best way to sort them? Thank you. //populate data object with data from xml file. //Data is a comma delimited list of values var jsData = new Array(); jsData = {lib: "#field...
15
1899
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 two? (1)
7
2444
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
1313
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 in this situation but I am having trouble getting access to properties at the presentation level. So my situation is I have a Vehicle base class. Public Class Vehicle Property BodyType as String End Class
2
349
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 do sys.setdefaultencoding = 'iso−8859−1' secondly the following does not give a 'UnicodeError: ASCII encoding error:', and I would expect ti to. In fact it prints out the n with ~
5
2474
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 need to add properties to a function object and access them within the function when it is executing. Therefore, I need to be
7
3210
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 bastard so posting it before I forgot again... By taking this minimum code: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"> <html> <head>
0
8444
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8869
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8781
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
6198
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5664
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4368
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2771
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2011
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1775
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.