Greetings everyone. I just jumped into Python for the first time this weekend and I'm finding it to be a very easy and enjoyable learning process. This forum has been particularly useful for finding code snippets and answers to questions that I ran into and others had posted about. So that's why I'm here, now posting for the first time.

After starting with a rather ambitious idea for my first project, I decided to take a step back and stick with text-based applications for a while so I can get a good grasp of the language before moving into GUI/graphics territory. Last night I started working on my second program that will be a text-based, turn-based medieval arena combat game. But it was my work on that, and my years of playing single and multi-player role playing games (MUDs in particular) that have me wondering about how to do something within a text-based game. And because my programming experience prior to starting Python has been 99% ASP/Javascript/SQL, maybe I'm just not aware of a very simple answer.

If you've ever played a MUD before, or even a game like World of Warcraft, the game world is always moving. It's alive. How do you do that? For my arena game everything progresses as a result of a user action. But I would really love to know how to make it so that if I am in my arena game, and I don't do anything, that my computer-controlled opponent would still be attacking me.

I think I understand the idea of what I'm talking about in terms of programming, but I have no idea how to actually code it. Rather than creating a loop that stops during each cycle in order to get user input, the loop would have to continue processing over and over while keeping an eye out for user input and also while managing computer-controlled items/beings/etc. Hence the idea that the game world is living in some way.

Thanks in advance for any responses, and for the great forum/site as well!

This looks to me like you are going to be going into threads and mutex. You should have a good look on google on how to use threads.

You could spawn a new thread to control the Opponents attacks, since they require no user imput all that would be happening is one thread is sitting waiting for the user to type something in whilst the other constantly modifies some variable such as the players HP. Which is where MUTEX comes in. Becuase there is a chance that the user will input data at the same time as the opponent tries to attack you may be trying to access the same variable at the same time...but with mutex locks that is easily fixed.

The best part about this is, lets say as you progress through the game you wanted to face 2 or 3 opponents. It should be easy enough to control this as you can just spawn another thread which attacks the user.

Note you can use some for of sleep to wait inbetween each of the opponents attacks.

I hope this information has been helpful to you.

BTW: Excellent first post, other users should read and learn from this

Chris

Chris, thanks for the response.

Threads! Yes, how could I have forgotten about threads? I read about them some time ago when I was helping a co-worker with some weird software package she maintains. I guess it's a case of forgetting about stuff that I don't deal with on a regular basis.

I've already done a little bit of reading about threading, mutex, and locking, and this certainly sounds like what I was describing. Without going into much detail, based on personal experience (assuming you have been down this road) would you describe programming with threads as complicated and/or difficult?

Thanks again!

Yer thats normally the case, every programmer i know gets rusty after not using something for a short period of time.

I've breifly looked into threads whilst i was developing a chat application and no i don't think they are too complex, once you have your base class set up. Which is not too difficult nor complicated.

You may find these links helpful
http://www.devshed.com/c/a/Python/Basic-Threading-in-Python/3/
http://www.python.org/doc/2.5.2/lib/module-threading.html
http://effbot.org/librarybook/threading.htm
ftp://ftp.fzu.cz/pub/unix/python/lib/module-mutex.html

Chris

Yeah threads is fairly easy once you get your head round it

Never used them in python (mainly a c# man myself, where i used them for a peer to peer chat application which could send/recieve simultaneously)

A good grasp of threads and OOP is essential for making something like a MUD,

This article has been dead for over six months. Start a new discussion instead.