My First Text Rpg (need help)

Started by
10 comments, last by Sria 17 years, 10 months ago
Okay, as you can see from the title, this is my first text rpg. Don't laugh, when I started out I went pong->tetris->pac-man->3d stuff. This is because, well, I have never played a text rpg before now. Now that I have, I love the concept because you can make a very large game without the hassle of doing all the art. So now I need help. You see, most of my programming experience is in Cplusplus.But lately I've gotten interested in Python because of its ease of use and development speed. Several people have told me that it is very good for text rpgs. Is this true? If so, how would I go about doing it? I'm still learning the basics of the language, so any examples would help alot. [Edited by - FullThrottle on June 7, 2006 2:32:08 PM]
-Kyle
Advertisement
For something like a text RPG, the language really isn't going to matter. Any language would work. Learning Python would be a good idea, however, as it will improve your knowledge of programming in general. I suggest you get Python and try out a few simple tasks to see if you like the language. If you do, then continue learning it and use it to make your text RPG.


Good luck!
hippopotomonstrosesquippedaliophobia- the fear of big words
Python is much better/easier at string processing, which is most of what a text game is. So yes, Python is a great language to look into.

Check out my new game Smash and Dash at:

http://www.smashanddashgame.com/

For a text based game, you really only need a few language constructs. You need a way to input/output text, a way to branch (if/else), and a way to loop (while/for). Pretty much any language is perfectly capable of this. I recommend using Python for the sake of learning a new language. It really won't matter for this project, but knowing several languages is very useful later on.
Sean Henley [C++ Tutor]Rensselaer Polytechnic Institute
Thanks everybody! FYI, I had already downloaded Python 2.4 and PyGame a while ago, and am learning at a slow-average pace (for some reason not as fast as I did Cplusplus...Wierd huh?)

@Sr_Guapo-> I can do all those thing with Cplusplus, but in Python I can't find how to do user input. Should I just use Cplusplus for the rpg or keep working on Python to use it for its ease of use?

P.S.- Ratings up for you guys for helping me!
-Kyle
Quote:Original post by FullThrottle
in Python I can't find how to do user input.


The Python function for getting user input is raw_input(). Here is an example:
s = raw_input("Please enter a string:")

The string you pass to raw_input is the prompt to be displayed when asking the user for input. After calling this function, s would contain whatever string the user entered.
------------------------------Support the Blue Skies in Games Campaign!A blog... of sorts.As a general rule, if you don't have a general rule in your signature, you aren't as awesome as someone who does. General rules roxor teh big one one ones.
Cool, thanks. So at the beginning of the game it would ask the name, and it would look like n=raw_input("What is your name brave warrior: "). But how would you do things like purchasing spells, travelling or combat? I would be very grateful for examples on how to set up these options.
-Kyle
Quote:Original post by FullThrottle
Cool, thanks. So at the beginning of the game it would ask the name, and it would look like n=raw_input("What is your name brave warrior: "). But how would you do things like purchasing spells, travelling or combat? I would be very grateful for examples on how to set up these options.


For travelling, you might want to set up a data structure (of some sort; I'm not too well versed in the minutiae of Python lists and dictioaries, check the docs for more info) containing the name of each location, the rooms of that location, monsters, etc. At the appropriate times, ask the player which direction they want to move, and update their map position accordingly.

For shops, you could output a list of available items, have the user type in the item they want, make sure they have available funds, and if so, put the item in their inventory (a Player class would be useful in organizing such information).

As for combat, encounters could occur on a random basis each time the player moves on a map. From there, you could ask the player which action they wanted to perform (like attack, item, run, etc.) and then perform the necessary data modification (subtract/add to health, remove an inventory item, etc.). Of course, there are multiple ways to implement any feature; these are just some suggestions.

Some Python code you will find useful: print"" is used whenever you need to display text (it's a keyword and not a function, so you just enter a string without parenthesis). The random module (import random) can generate random numbers, classes are very similar to those in C++ (no private or public members, and the class constructor is called __init__), and lists and dictionaries are Python's versions of arrays. Anytime you need help while working in the Python interpreter, just type help("function or module name") to recieve tons of built-in documentation. The Python docs included with the SDK will also be a big asset.

Best of luck to you!
------------------------------Support the Blue Skies in Games Campaign!A blog... of sorts.As a general rule, if you don't have a general rule in your signature, you aren't as awesome as someone who does. General rules roxor teh big one one ones.
One thing that is really nice (that PW touched on above) is that the Dictionary type is built into Python. All of your rooms/spells/etc can be accessed by name in a very simple and logical manner ( Spells["Fire"], Rooms["Dungeon"] or something like that... been a while since I've Pythoned ).

Sure, C++ has the map<> type, but it's not nearly as clean and flexible.

Check out my new game Smash and Dash at:

http://www.smashanddashgame.com/

Thank you so much guys for all the help. I have one more question that's about combat. I was to hoping to do random.choice(["hit","miss"]) to see if an attack/spell hits, then do random.sample(xrange(10),10) for a weapon like a dagger to calculate how much damage is given. But how would I set it up to make the random number when it chooses hit?
-Kyle

This topic is closed to new replies.

Advertisement