Re: [pygame] Text-Based RPG

2007-06-19 Thread Luke Paireepinart

Jonah Fishel wrote:

You guys are geniuses.
Haha you probably work for big corporations and stuff that do this for 
a living and Iʻm just a 13 year old kid who found Python on my Mac!

Thank you anyway!

There are lots of great tutors in the Python community.
The pygame list welcomes people of all skill levels, of course, but if 
you'd like to try a mailing list that's dedicated solely to helping you 
master Python,

you should look into the Python Tutor mailing list.
Since your game doesn't actually use 'pygame,' as it's a text game, you 
should be able to get help with anything you need on that mailing list.
of course, once you start upgrading it with awesome 3d models, you'll 
probably need to come back here to ask your questions, but for now, I 
think you should look into the Tutor list as an alternate source of 
wisdom and advice.  The guys on there are really nice.

HTH,
-Luke




Re: [pygame] Text-Based RPG

2007-06-19 Thread Jonah Fishel

You guys are geniuses.
Haha you probably work for big corporations and stuff that do this  
for a living and Iʻm just a 13 year old kid who found Python on my Mac!

Thank you anyway!

On Jun 19, 2007, at 6:34 PM, [EMAIL PROTECTED] wrote:


On Tue, June 19, 2007 7:38 pm, Jonah Fishel wrote:

def ProcessCommand(current_room): """CommandLine processor"""
words = comm.split() if words[0] == 'north': MoveNorth(current_room)


About this section: Try typing a blank line as your command and  
you'll get
an error, because words will be a blank list( [] ) and words[0]  
will be

outside the allowed range. I suggest sanity-checking by counting the
number of words:
number_of_words = len(words)
if number_of_words > 1:
## Do stuff that requires more than one word


elif words[0] == 'south': MoveSouth(current_room)
elif words[0] == 'west': MoveWest(current_room)
elif words[0] == 'east': MoveEast(current_room)
elif words[0] == 'up': MoveUp(current_room)
elif words[0] == 'down': MoveDown(current_room)


These probably don't need unique functions. Why not one function that
takes a direction parameter? Or have a class that keeps track of the
current room, so there's no need to pass the current room each time?


if room_to_go_n.exits[0] == 'north':


This line won't work if the exits are stored as a dictionary, because
you're trying to access it like a list. If you want the keys in a
dictionary:

dict = {"bacon":True,"eggs":True,"spam":True}
dict.keys()

["bacon","eggs","spam"]

But dictionaries don't store the keys in any predictable order, so  
don't

count on the "first" key being the one you want. How about:
if room.exits.get("north"):
## Then the dictionary has an entry like:
## {"north":True}
## If the value for "north" is False, or if there _is_ no  
north, the if
## statement will be false. You could also ask, "if room.exits 
['north']"

## but that'll crash if the key doesn't exist.

Or if every room can only have exits in standard directions like  
"north"
instead of unique exits like "stairs", you could use a list where  
entry 0
is always north, 1 is east, and so on. That might make more sense  
than a

dictionary. I would then have constants like:
NORTH = 0

so that you can then say:
if room.exits[NORTH]: ## ...

Yet another way to navigate would be to have each room have XYZ
coordinates, so that if the current room is (0,0,0) and the player  
wants
to go north, you might check for an existing room with coords  
(0,-1,0).


tavernbackroom.exits = ['none', 'south', 'none', 'none', 'none',  
'none']

tavernbackroom.text = open('tavern_backroom.txt', 'r')
tavernbackroom.current_room = tavernbackroom


I suspect you're misusing the open statement. That command creates  
an open

"file object," but doesn't actually give you its contents. If you just
want to pull the text out of the file, try:
f = open("whatever.txt","r")
text = f.read() ## Get the file's text
f.close()

In Windows at least, I find that if my program crashes while I've  
got a

file open, the OS complains if I try to delete the file.





Re: [pygame] Text-Based RPG

2007-06-19 Thread kschnee
On Tue, June 19, 2007 7:38 pm, Jonah Fishel wrote:
> def ProcessCommand(current_room): """CommandLine processor"""
> words = comm.split() if words[0] == 'north': MoveNorth(current_room)

About this section: Try typing a blank line as your command and you'll get
an error, because words will be a blank list( [] ) and words[0] will be
outside the allowed range. I suggest sanity-checking by counting the
number of words:
number_of_words = len(words)
if number_of_words > 1:
## Do stuff that requires more than one word

> elif words[0] == 'south': MoveSouth(current_room)
> elif words[0] == 'west': MoveWest(current_room)
> elif words[0] == 'east': MoveEast(current_room)
> elif words[0] == 'up': MoveUp(current_room)
> elif words[0] == 'down': MoveDown(current_room)

These probably don't need unique functions. Why not one function that
takes a direction parameter? Or have a class that keeps track of the
current room, so there's no need to pass the current room each time?

> if room_to_go_n.exits[0] == 'north':

This line won't work if the exits are stored as a dictionary, because
you're trying to access it like a list. If you want the keys in a
dictionary:
>>> dict = {"bacon":True,"eggs":True,"spam":True}
>>> dict.keys()
["bacon","eggs","spam"]

But dictionaries don't store the keys in any predictable order, so don't
count on the "first" key being the one you want. How about:
if room.exits.get("north"):
## Then the dictionary has an entry like:
## {"north":True}
## If the value for "north" is False, or if there _is_ no north, the if
## statement will be false. You could also ask, "if room.exits['north']"
## but that'll crash if the key doesn't exist.

Or if every room can only have exits in standard directions like "north"
instead of unique exits like "stairs", you could use a list where entry 0
is always north, 1 is east, and so on. That might make more sense than a
dictionary. I would then have constants like:
NORTH = 0

so that you can then say:
if room.exits[NORTH]: ## ...

Yet another way to navigate would be to have each room have XYZ
coordinates, so that if the current room is (0,0,0) and the player wants
to go north, you might check for an existing room with coords (0,-1,0).

> tavernbackroom.exits = ['none', 'south', 'none', 'none', 'none', 'none']
> tavernbackroom.text = open('tavern_backroom.txt', 'r')
> tavernbackroom.current_room = tavernbackroom

I suspect you're misusing the open statement. That command creates an open
"file object," but doesn't actually give you its contents. If you just
want to pull the text out of the file, try:
f = open("whatever.txt","r")
text = f.read() ## Get the file's text
f.close()

In Windows at least, I find that if my program crashes while I've got a
file open, the OS complains if I try to delete the file.



Re: [pygame] Text-Based RPG

2007-06-19 Thread Dave LeCompte (really)
"Jonah Fishel" <[EMAIL PROTECTED]> wrote:


> tavern = Room()
[...]
> tavernbackroom = Room()
[...]
> tavern.room_north = tavernbackroom()
[...]
> When I try to run this test program, it says that "AttributeError:
> Room instance has no __call__ method"

The problem you're hitting here is that you're creating two instances of
the room class, tavern and tavernbackroom, and then you're attempting to
call tavernbackroom, and assign that to the room_north attribute of
tavern.

You probably would rather do

tavern.room_north = tavernbackroom

with no parens.


Another way you could implement this would be to make the exits a
dictionary instead of a list, and then hook up rooms like so:

tavern.exits['north']=tavernbackroom



We're sort of getting afield from PyGame discussion and into Python style,
but a few more suggestions:

> tavern.DisplayRoom(tavern)

I wouldn't do this - you're creating a class method and passing an
instance into it. Instead, I'd create an instance method, and call it
directly, like so:

def DisplayRoom(self):
"""Displays text for a room"""
print self.text
print self.exits.keys()

and then, the display would look more like:

tavern.DisplayRoom()


Also, the call to close() inside the display seems like it's in the wrong
place - it's best to have file reading code separated from display
(loading probably happens once, and display could happen many times), so
maybe you'd want to do something like:

def LoadDescription(self, filename):
  file=open(filename,r)
  self.text=file.read()
  file.close()


and then your description text line would look more like this:

tavern.LoadDescription('swamp_tavern.txt')


-Dave LeCompte


Re: [pygame] Text-Based RPG

2007-06-19 Thread Laura Creighton
In a message of Tue, 19 Jun 2007 15:38:22 EDT, Jonah Fishel writes:
>You guys are really awesomely smart BUT I'm dumb, so:
>class Room:
> def __init__(self):
> exits = {} # Create a dictionary of exits- depending on ID,  
>there could be different exits
> self.Id = None # ID starts at 0, but different rooms have  
>different ID



>
>tavern = Room()
>tavern.Id = 1
>tavern.name = 'Anthropophagi Tavern'
>tavern.exits = ['north', 'south', 'none', 'none', 'none', 'down']
>tavern.text = open('swamp_tavern.txt', 'r')
>tavern.current_room = tavern()
>
>tavernbackroom = Room()
>tavernbackroom.Id = 2
>tavernbackroom.name = 'Tavern Backroom'
>tavernbackroom.exits = ['none', 'south', 'none', 'none', 'none', 'none']
>tavernbackroom.text = open('tavern_backroom.txt', 'r')
>tavernbackroom.current_room = tavernbackroom
>
>tavern.room_north = tavernbackroom()
>
>tavern.DisplayRoom(tavern)
>tavern.CommandLine()
>
>When I try to run this test program, it says that "AttributeError:  
>Room instance has no __call__ method"
>Is __call__ like __init__?

It can be.  In Python you are allowed to write your own __call__
method.  But it is very unlikely that you will ever need to in the
course of this game.   Most things that you want to call will
already be callable.  functions are callable.  methods of
classes are callable.  You don't need to do anything to make them
that way -- they come that way right out of the box.

Classes, however, aren't callable.  And somewhere up there you have
tried to call one.  The thing to look for is a set of () that
do not belong.  (It could be a (with, some, arguments, inside)
but it's usually a spurious set of ().  

Aha, there it is ...

tavern.room_north = tavernbackroom()

tavernbackroom is an instance of the Room class.  You cannot call it.
take away the parens and things will work fine.

Laura



Re: [pygame] Text-Based RPG

2007-06-19 Thread Marius Gedminas
On Tue, Jun 19, 2007 at 10:22:13AM -0400, Jonah Fishel wrote:
> Thank you very much. I was very helpful.
> Trogdor... that's great. I gotta use that word in the game =)

http://en.wikipedia.org/wiki/Trogdor

Marius Gedminas
-- 
Added mysterious, undocumented --scanflags and --fuzzy options.
-- nmap 3.0 announcement


signature.asc
Description: Digital signature


Re: [pygame] Text-Based RPG

2007-06-19 Thread Jonah Fishel



You guys are really awesomely smart BUT I'm dumb, so:
class Room:
def __init__(self):
exits = {} # Create a dictionary of exits- depending on ID,  
there could be different exits
self.Id = None # ID starts at 0, but different rooms have  
different ID

self.name = None # ^^^
self.exits = []
self.text = None
self.comm = None
self.current_room = None
def DisplayRoom(current_room):
"""Displays text for a room"""
print current_room.text.read
print current_room.exits
current_room.text.close()
def CommandLine():
comm = raw_input('>>> ')
return comm
ProcessCommand()
def ProcessCommand(current_room):
"""CommandLine processor"""
words = comm.split()
if words[0] == 'north':
MoveNorth(current_room)
elif words[0] == 'south':
MoveSouth(current_room)
elif words[0] == 'west':
MoveWest(current_room)
elif words[0] == 'east':
MoveEast(current_room)
elif words[0] == 'up':
MoveUp(current_room)
elif words[0] == 'down':
MoveDown(current_room)
else:
raise 'Error. Invalid command.'
def MoveNorth(room_to_go_n):
if room_to_go_n.exits[0] == 'north':
room_north()
else:
print "You can't go that way."

tavern = Room()
tavern.Id = 1
tavern.name = 'Anthropophagi Tavern'
tavern.exits = ['north', 'south', 'none', 'none', 'none', 'down']
tavern.text = open('swamp_tavern.txt', 'r')
tavern.current_room = tavern()

tavernbackroom = Room()
tavernbackroom.Id = 2
tavernbackroom.name = 'Tavern Backroom'
tavernbackroom.exits = ['none', 'south', 'none', 'none', 'none', 'none']
tavernbackroom.text = open('tavern_backroom.txt', 'r')
tavernbackroom.current_room = tavernbackroom

tavern.room_north = tavernbackroom()

tavern.DisplayRoom(tavern)
tavern.CommandLine()

When I try to run this test program, it says that "AttributeError:  
Room instance has no __call__ method"

Is __call__ like __init__?

You certainly could make a Tavern Room subclass of the Room class,  
but it
probably makes more sense to make a generic Location class, and  
then use
data (loaded from text files like I think you're already doing, or  
loading
from a database, or... any number of other data-driven solutions)  
to give
it the specific characteristics that you want (Dark Room, Tavern,  
Cave, In

Front of House, Flood Control Gate #8).






Re: [pygame] Text-Based RPG

2007-06-19 Thread Kamilche

Kris Schnee wrote:


What's different about the tavern versus a regular room? Most likely 
it's just some variables that you might as well put into a single Room 
class. For instance, if a room can be light or dark, you could give the 
Room class a "light" variable by putting in the __init__ function:
self.light = options.get("light",True) ## Which makes True the default 
value




Or:

class Room(object):
name = 'Room'
light = 1


class Tavern(Room):
name = 'Tavern'
light = 0


Then, at startup time, store the type of the room in the data, so you 
know which variable to instantiate at startup time.


It's a matter of preference, but I don't like stuffing data into 
variables on __init__ unless I have to.


Re: [pygame] Text-Based RPG

2007-06-19 Thread massimo s.
Jonah Fishel ha scritto:
> I've been away from Python for several months. I just came back to it,
> to start working on a text-based RPG. To get started, I decided to move
> by rooms. I have separate text files for each major message, to conserve
> file space. What troubles me is that when I tested it, whenever I enter
> anything into the command line, it says 'Invalid command' which I
> included as an error message. Here is where I think the trouble is:

Why, instead of writing your own command line, don't you use the cmd
Python module?

It allows to build command line interfaces very quickly and manages a
lot of things for you.

m.


Re: [pygame] Text-Based RPG

2007-06-19 Thread Kris Schnee

Dave LeCompte (really) wrote:

"Jonah Fishel" <[EMAIL PROTECTED]> was asking:


Could I make a Room class that has functions based on different
variables and then make a separate class for each room like
AnthroTavern(Room) so I could base it on the rom class and use the
functions for the room class?



So, the answer to "Could I make a class..." is "yes". A good next question
would be "would I want to?", and in this case I think the answer is "no".

You certainly could make a Tavern Room subclass of the Room class, but it
probably makes more sense to make a generic Location class, and then use
data (loaded from text files like I think you're already doing, or loading
from a database, or... any number of other data-driven solutions) to give
it the specific characteristics that you want (Dark Room, Tavern, Cave, In
Front of House, Flood Control Gate #8).



Dave LeCompte is right. This is my take on the issue:

What's different about the tavern versus a regular room? Most likely 
it's just some variables that you might as well put into a single Room 
class. For instance, if a room can be light or dark, you could give the 
Room class a "light" variable by putting in the __init__ function:

self.light = options.get("light",True) ## Which makes True the default value

One way to manage movement between rooms would be to have a RoomManager 
class that has a database of rooms, each with an index, so that each 
room can have a variable like "exits" that gives indexes of each room 
that it leads to. I'm not sure whether it's better programming practice 
to have these exits be the rooms' ID numbers or actual references:

exits = {} ## Create a dictionary
tavern = Room(name="Anthro Tavern",ID=42) ## Make a room
## Method 1:
exits["north"] = tavern.ID
exits.get("north") ## returns the number 42
## Method 2:
exits["north"] = tavern
exits.get("north") ## Returns the actual Room

I was playing with the idea of doing a text adventure earlier... 
actually at several points. Here's the code for the most recent 
experiment with that; you're welcome to copy/steal/use any of it, though 
it's poorly commented and maybe not well-designed.




Re: [pygame] Text-Based RPG

2007-06-19 Thread Dave LeCompte (really)
"Jonah Fishel" <[EMAIL PROTECTED]> was asking:

> Could I make a Room class that has functions based on different
> variables and then make a separate class for each room like
> AnthroTavern(Room) so I could base it on the rom class and use the
> functions for the room class?

I had a manager once, his motto was "this is software, we can do anything".

So, the answer to "Could I make a class..." is "yes". A good next question
would be "would I want to?", and in this case I think the answer is "no".

You certainly could make a Tavern Room subclass of the Room class, but it
probably makes more sense to make a generic Location class, and then use
data (loaded from text files like I think you're already doing, or loading
from a database, or... any number of other data-driven solutions) to give
it the specific characteristics that you want (Dark Room, Tavern, Cave, In
Front of House, Flood Control Gate #8).

Writing code for each specific location is a lot more work, and probably
going to give you redundant code, and more errors.

This is just one page discussing data driven programming:
http://www.faqs.org/docs/artu/ch09s01.html


-Dave LeCompte




Re: [pygame] Text-Based RPG

2007-06-19 Thread Jonah Fishel


Could I make a Room class that has functions based on different  
variables and then make a separate class for each room like  
AnthroTavern(Room) so I could base it on the rom class and use the  
functions for the room class?


Yes, you could (and should). It looks like you're handling each  
room and

action as a special case, which means a lot of repeated work. For
instance, you have several commands for "talk to [person]". What if  
you

processed the input a bit more, like so:




RE: [pygame] Text-Based RPG

2007-06-19 Thread Chris Ashurst
Don't forget to add "Trogdor.burninate(people)" ;)

-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
Behalf Of Jonah Fishel
Sent: Tuesday, June 19, 2007 10:22
To: pygame-users@seul.org
Subject: Re: [pygame] Text-Based RPG


Thank you very much. I was very helpful.
Trogdor... that's great. I gotta use that word in the game =)

> self.some_other_variable = "Trogdor"




CONFIDENTIAL NOTICE: This email including any attachments, contains 
confidential information belonging to the sender. It may also be 
privileged or otherwise protected by work product immunity or other 
legal rules. This information is intended only for the use of the 
individual or entity named above.  If you are not the intended 
recipient, you are hereby notified that any disclosure, copying, 
distribution or the taking of any action in reliance on the contents 
of this emailed information is strictly prohibited.  If you have 
received this email in error, please immediately notify us by 
reply email of the error and then delete this email immediately.


Re: [pygame] Text-Based RPG

2007-06-19 Thread Jonah Fishel

Thank you very much. I was very helpful.
Trogdor... that's great. I gotta use that word in the game =)


self.some_other_variable = "Trogdor"




Re: [pygame] Text-Based RPG

2007-06-18 Thread Casey Duncan

On Jun 18, 2007, at 3:44 PM, [EMAIL PROTECTED] wrote:


On Mon, June 18, 2007 4:58 pm, Dave LeCompte (really) wrote:
Other folks have talked about returning values, which is good, but  
this

line makes me uneasy:


def command(command, current_room):


I'd stay away from using the same name for more than one thing. In  
this

case, you're naming the argument the same thing as the function...


As a side note: That's part of why I like using ThisFormat for  
function

names and lowercase_format for variable names. Doing so makes it more
obvious what each thing is. At worst you'd be calling "Command 
(command)".




To that end, this may interest you:

http://www.python.org/dev/peps/pep-0008/

-Casey



Re: [pygame] Text-Based RPG

2007-06-18 Thread kschnee
On Mon, June 18, 2007 4:58 pm, Dave LeCompte (really) wrote:
> Other folks have talked about returning values, which is good, but this
> line makes me uneasy:
>
>> def command(command, current_room):
>
> I'd stay away from using the same name for more than one thing. In this
> case, you're naming the argument the same thing as the function...

As a side note: That's part of why I like using ThisFormat for function
names and lowercase_format for variable names. Doing so makes it more
obvious what each thing is. At worst you'd be calling "Command(command)".



Re: [pygame] Text-Based RPG

2007-06-18 Thread kschnee
On Mon, June 18, 2007 8:57 pm, Jonah Fishel wrote:

>> I don't really have a good enough grasp of classes to implement
>> them. Could I make a RoomManager class?
>
>> Also you should look up how 'class'es work. Using them would make
>> this easier.


Here's one I know enough to answer! 8)

Yes, you could (and should). It looks like you're handling each room and
action as a special case, which means a lot of repeated work. For
instance, you have several commands for "talk to [person]". What if you
processed the input a bit more, like so:

## Where "command" is a string with what the user typed:
words = command.split() ## Split into a list of words, found by searching
for spaces (by default; but try eg. split(","))
if words[0] == "talk":
person_to_talk_to = words[1]

Looking for specific words like that does require that you check for how
many words there are, though (using len(words)); the above code would
crash if the user typed a blank line or just "talk".

Classes don't have to be scary. The only arcane bit of setup is this:

class MyClass:
"""Put comments here"""
def __init__(self): ## Has to be called __init__
self.some_variable = 42
self.some_other_variable = "Trogdor"

Then you define functions within the class, and make an actual instance of
the class by saying:
x = MyClass()

Then you can access it like so:
x.some_variable ## Returns the number 42

Even without getting into functions (besides that automatic setup
function), the usefulness of a class like this is that you can easily keep
track of a group of related variables, like all the information about a
single room.

A suggestion for one way to set up a class:

class Knight:
def __init__(self,**options):
self.name = options.get("name","Robin") ## The second is a default
value
self.airspeed_velocity = options.get("airspeed_velocity") ##
Default is None

## Now create an instance:
arthur = Knight(name="Arthur",hit_points=999)
## Since "hit points" isn't referred to in the class setup, it gets
ignored harmlessly.

Hopefully this will be useful.



Re: [pygame] Text-Based RPG

2007-06-18 Thread Jonah Fishel


I don't really have a good enough grasp of classes to implement  
them. Could I make a RoomManager class?


Also you should look up how 'class'es work. Using them would make  
this easier.




Re: [pygame] Text-Based RPG

2007-06-18 Thread space coyote

On 6/18/07, Jonah Fishel <[EMAIL PROTECTED]> wrote:


I've been away from Python for several months. I just came back to
it, to start working on a text-based RPG. To get started, I decided
to move by rooms. I have separate text files for each major message,
to conserve file space. What troubles me is that when I tested it,
whenever I enter anything into the command line, it says 'Invalid
command' which I included as an error message. Here is where I think
the trouble is:

def command_line():
 command = raw_input('>>> ')
def command(command, current_room):
 if current_room == anthro_tavern:
 if command == 'north':
 print '\n\nThat room does not exist yet. Please try
again.\n\n'
 elif command == 'south':
 print '\n\nThat room does not exist yet. Please try
again.\n\n'
 elif command == 'down':
 print 'That room does not exist yet. Please try again./n/n'
 elif command == 'talk to garrick':
 speech = open('garricks_speech.txt', 'r')
 print speech.read()
 speech.close()
 elif command == 'talk to janet':
 speech = open('janets_speech.txt', 'r')
 print speech.read()
 speech.close()
 elif command == 'talk to stranger':
 print 'This feature is coming soon.'
 else:
 print 'Invalid command.'
 anthro_tavern()
 else:
 print 'Error 1: Non existent room being requested/nfrom. If
this error appears, something/nis very wrong.'
def anthro_tavern():
 text_file = open("swamp_tavern.txt", "r")
 print text_file.read()
 text_file.close()
 command(command_line(), anthro_tavern)
 return current_room

anthro_tavern()

I originally had different commands for each action, with variations
on capitalization so you didn't have to enter the same command every
time, but then all it did was the message for the first 'if' line.
Does anyone see a problem with this?



Besides the suggestion to use .strip(), you could also use .split(). For
example:

a = 'say hello'
print a.split()

prints:
['say', 'hello']

Then you have a list. So you can use the first argument as the command and
have a function for each command that parses the other arguments and
produces the desired result.

So if you go:
a = 'say hello'
b = a.split()

then you can go:
if b[0] = 'say':
   say(b)

I hope you understand what I'm saying :)

Also you should look up how 'class'es work. Using them would make this
easier.


Re: [pygame] Text-Based RPG

2007-06-18 Thread Dave LeCompte (really)
"Jonah Fishel" <[EMAIL PROTECTED]> is working on a text adventure:

Other folks have talked about returning values, which is good, but this
line makes me uneasy:

> def command(command, current_room):

I'd stay away from using the same name for more than one thing. In this
case, you're naming the argument the same thing as the function - it's
probably OK in this case where the scoping does the right thing, but it's
way too easy to get name collisions in Python - accidentally blocking a
global by assigning a local value to it.

One problem you'd get into with this particular example would be if you
wanted to implement a "tell" command that operated something like this:

>>> tell sailor, go north

You might implement that as a recursive call that pulls out the name of
the individual the player's talking to, and takes the rest of the line
(leaving aside the issues of making sure the punctuation's cleaned up) and
does a recursive call - you'd want to call the function "command" from
within itself, but the argument "command" keeps the function "command"
from being seen.

I'd rewrite it a little like this:

def parse_command(command_string, cur_room):

and you should be in good shape.


-Dave LeCompte


Re: [pygame] Text-Based RPG

2007-06-18 Thread Jonah Fishel


As separate html pages for each room/action? I would think not. I  
would think programatically generating the pages would be easier,  
and would be infinitely more flexible. This a web-based game?

Not really. I just wanted to know.


Re: [pygame] Text-Based RPG

2007-06-18 Thread Jonah Fishel

Thank you guys! It worked. Now I see what went wrong.

On Jun 18, 2007, at 12:43 PM, John Krukoff wrote:


-Original Message-
From: [EMAIL PROTECTED] [mailto:owner-pygame- 
[EMAIL PROTECTED] On

Behalf Of Jonah Fishel
Sent: Monday, June 18, 2007 10:30 AM
To: pygame-users@seul.org
Subject: [pygame] Text-Based RPG

I've been away from Python for several months. I just came back to
it, to start working on a text-based RPG. To get started, I decided
to move by rooms. I have separate text files for each major message,
to conserve file space. What troubles me is that when I tested it,
whenever I enter anything into the command line, it says 'Invalid
command' which I included as an error message. Here is where I think
the trouble is:

def command_line():
 command = raw_input('>>> ')
def command(command, current_room):
 if current_room == anthro_tavern:
 if command == 'north':
 print '\n\nThat room does not exist yet. Please try
again.\n\n'
 elif command == 'south':
 print '\n\nThat room does not exist yet. Please try
again.\n\n'
 elif command == 'down':
 print 'That room does not exist yet. Please try  
again./n/n'

 elif command == 'talk to garrick':
 speech = open('garricks_speech.txt', 'r')
 print speech.read()
 speech.close()
 elif command == 'talk to janet':
 speech = open('janets_speech.txt', 'r')
 print speech.read()
 speech.close()
 elif command == 'talk to stranger':
 print 'This feature is coming soon.'
 else:
 print 'Invalid command.'
 anthro_tavern()
 else:
 print 'Error 1: Non existent room being requested/nfrom. If
this error appears, something/nis very wrong.'
def anthro_tavern():
 text_file = open("swamp_tavern.txt", "r")
 print text_file.read()
 text_file.close()
 command(command_line(), anthro_tavern)
 return current_room

anthro_tavern()

I originally had different commands for each action, with variations
on capitalization so you didn't have to enter the same command every
time, but then all it did was the message for the first 'if' line.
Does anyone see a problem with this?



You'll probably get a bunch of suggestions for how to improve the  
overall
structure of things here, but the reason why your sample isn't  
working like
you expect it to is because your command_line() function isn't  
returning a
value. Since it doesn't have an explicit return, the value your  
command()
function is seeing is None, which is what would be printed if you  
put a

'print command' line at the top of your command() function.

Try this instead:
def command_line():
  return raw_input('>>> ')

As a suggestion for dealing with capitilization variations, take a  
look at

the lower string method.
-
John Krukoff
[EMAIL PROTECTED]








Re: [pygame] Text-Based RPG

2007-06-18 Thread Casey Duncan

On Jun 18, 2007, at 9:41 AM, Jonah Fishel wrote:


Nope. Sorry. I'm new to Python- what does strip() do?


strip() trims leading and trailing whitespace. In any case my  
suggestion won't work, because as Will pointed out, the command_line 
() function doesn't return anything. Try this:


def command_line():
return raw_input('>>> ').strip()


And would this be easier to write in HTML?


As separate html pages for each room/action? I would think not. I  
would think programatically generating the pages would be easier, and  
would be infinitely more flexible. This a web-based game?


-Casey





RE: [pygame] Text-Based RPG

2007-06-18 Thread John Krukoff
> -Original Message-
> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On
> Behalf Of Jonah Fishel
> Sent: Monday, June 18, 2007 10:30 AM
> To: pygame-users@seul.org
> Subject: [pygame] Text-Based RPG
> 
> I've been away from Python for several months. I just came back to
> it, to start working on a text-based RPG. To get started, I decided
> to move by rooms. I have separate text files for each major message,
> to conserve file space. What troubles me is that when I tested it,
> whenever I enter anything into the command line, it says 'Invalid
> command' which I included as an error message. Here is where I think
> the trouble is:
> 
> def command_line():
>  command = raw_input('>>> ')
> def command(command, current_room):
>  if current_room == anthro_tavern:
>  if command == 'north':
>  print '\n\nThat room does not exist yet. Please try
> again.\n\n'
>  elif command == 'south':
>  print '\n\nThat room does not exist yet. Please try
> again.\n\n'
>  elif command == 'down':
>  print 'That room does not exist yet. Please try again./n/n'
>  elif command == 'talk to garrick':
>  speech = open('garricks_speech.txt', 'r')
>  print speech.read()
>  speech.close()
>  elif command == 'talk to janet':
>  speech = open('janets_speech.txt', 'r')
>  print speech.read()
>  speech.close()
>  elif command == 'talk to stranger':
>  print 'This feature is coming soon.'
>  else:
>  print 'Invalid command.'
>  anthro_tavern()
>  else:
>  print 'Error 1: Non existent room being requested/nfrom. If
> this error appears, something/nis very wrong.'
> def anthro_tavern():
>  text_file = open("swamp_tavern.txt", "r")
>  print text_file.read()
>  text_file.close()
>  command(command_line(), anthro_tavern)
>  return current_room
> 
> anthro_tavern()
> 
> I originally had different commands for each action, with variations
> on capitalization so you didn't have to enter the same command every
> time, but then all it did was the message for the first 'if' line.
> Does anyone see a problem with this?

You'll probably get a bunch of suggestions for how to improve the overall
structure of things here, but the reason why your sample isn't working like
you expect it to is because your command_line() function isn't returning a
value. Since it doesn't have an explicit return, the value your command()
function is seeing is None, which is what would be printed if you put a
'print command' line at the top of your command() function.

Try this instead:
def command_line():
  return raw_input('>>> ')

As a suggestion for dealing with capitilization variations, take a look at
the lower string method.
-
John Krukoff
[EMAIL PROTECTED]





Re: [pygame] Text-Based RPG

2007-06-18 Thread Will McGugan

Jonah Fishel wrote:

I've been away from Python for several months. I just came back to  
it, to start working on a text-based RPG. To get started, I decided  
to move by rooms. I have separate text files for each major message,  
to conserve file space. What troubles me is that when I tested it,  
whenever I enter anything into the command line, it says 'Invalid  
command' which I included as an error message. Here is where I think  
the trouble is:


def command_line():
command = raw_input('>>> ')
def command(command, current_room):
if current_room == anthro_tavern:
if command == 'north':
print '\n\nThat room does not exist yet. Please try  
again.\n\n'

elif command == 'south':
print '\n\nThat room does not exist yet. Please try  
again.\n\n'

elif command == 'down':
print 'That room does not exist yet. Please try again./n/n'
elif command == 'talk to garrick':
speech = open('garricks_speech.txt', 'r')
print speech.read()
speech.close()
elif command == 'talk to janet':
speech = open('janets_speech.txt', 'r')
print speech.read()
speech.close()
elif command == 'talk to stranger':
print 'This feature is coming soon.'
else:
print 'Invalid command.'
anthro_tavern()
else:
print 'Error 1: Non existent room being requested/nfrom. If  
this error appears, something/nis very wrong.'

def anthro_tavern():
text_file = open("swamp_tavern.txt", "r")
print text_file.read()
text_file.close()
command(command_line(), anthro_tavern)
return current_room

anthro_tavern()



command_line doesnt appear to return anything, so the command will 
always be None.


Will


Re: [pygame] Text-Based RPG

2007-06-18 Thread Jonah Fishel

Nope. Sorry. I'm new to Python- what does strip() do?
And would this be easier to write in HTML?

On Jun 18, 2007, at 12:36 PM, Casey Duncan wrote:



On Jun 18, 2007, at 9:29 AM, Jonah Fishel wrote:


I've been away from Python for several months. I just came back to  
it, to start working on a text-based RPG. To get started, I  
decided to move by rooms. I have separate text files for each  
major message, to conserve file space. What troubles me is that  
when I tested it, whenever I enter anything into the command line,  
it says 'Invalid command' which I included as an error message.  
Here is where I think the trouble is:




Perhaps command has a trailing newline?

try this:

def command_line():
command = raw_input('>>> ').strip()

and see if that helps.

-Casey





Re: [pygame] Text-Based RPG

2007-06-18 Thread Casey Duncan


On Jun 18, 2007, at 9:29 AM, Jonah Fishel wrote:

I've been away from Python for several months. I just came back to  
it, to start working on a text-based RPG. To get started, I decided  
to move by rooms. I have separate text files for each major  
message, to conserve file space. What troubles me is that when I  
tested it, whenever I enter anything into the command line, it says  
'Invalid command' which I included as an error message. Here is  
where I think the trouble is:


Perhaps command has a trailing newline?

try this:

def command_line():
command = raw_input('>>> ').strip()

and see if that helps.

-Casey