Python newbie needs help

R

Ron Hudson

First let me apologize if this post offends, I am a real newbie to
Python having only used it for about
2 days. If this is the wrong place to post newbie questions, please
be polite.

I have the O'Reily Learning Python book and I am reading it.

Here's what I am working on..

I am trying to create something like a MUD, It will eventually evolve
to a multi player
MUD over the network game, but for now it's just a platform for
authoring and playing
text adventures that works like a single user MUD.

I am using a dictionary to hold the world.

I have a .py file with some def scripts(?) in it. right now it only
has scripts to
save and load the world dictionary.

I am using "Import" to read it after I start an interactive python.
What I need
right now is I seem to have some sort of scoping problems with the
world dictionary.

I can read it and write it and "world<cr>" lists it out. but my def
look(at): script
it seems it doesn't see the the "world" dictionary.
file "<stdin>" line ?
file lets.py line 14 in look
print world[at+'description']
nameError:world
>>> at = 'wizard'
>>> print world[at+'description'] A short guy wearing a robe and a pointy hat
>>>

Is there a way to make 'world' global? can I do it in lets.py?

Am I going about this all wrong?

Thanks.

P.S. Is there a way to tell python to "save my whole environment"
and to "reload my whole environment"
 
D

Dennis Benzinger

Ron said:
[...]
I have a .py file with some def scripts(?) in it.

def is the begining of a function definition.
[...]
I am using "Import" to read it after I start an interactive python.
What I need
right now is I seem to have some sort of scoping problems with the
world dictionary.

I can read it and write it and "world<cr>" lists it out. but my def
look(at): script
it seems it doesn't see the the "world" dictionary.
file "<stdin>" line ?
file lets.py line 14 in look
print world[at+'description']
nameError:world
at = 'wizard'
print world[at+'description'] A short guy wearing a robe and a pointy hat

Is there a way to make 'world' global? can I do it in lets.py?

Am I going about this all wrong?
[...]

The easiest solution for you would be a world variable in your lets
module. Then at the interactive prompt you could refer to it with
lets.world. So the loadworld function in lets.py would look like this:

def loadworld():
# Your loading code
global world
world = ...


Bye,
Dennis
 
K

Kent Johnson

Ron said:
I am trying to create something like a MUD, It will eventually evolve
to a multi player
MUD over the network game, but for now it's just a platform for
authoring and playing
text adventures that works like a single user MUD.

You might Google "python text adventure game" if you want to build on others' work instead
of starting from scratch.

Kent
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top