Jump to content

  • Log In with Google      Sign In   
  • Create Account

having multiple monsters in one text file

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
6 replies to this topic

#1   Members   


Posted 28 February 2013 - 01:56 PM

for a while in my text based game, monsters have been loaded via random variables applied to lists and that are therefore generated.


However, for a while i have wondered how i could have all the monster attributes in an easily modifiable text file containing all the data.


i know how it will work, what it do is for example, i will call foo.txt





bites #success verb

bite #fail verb 








the trouble is that i don't know what function to use as some of the information from help() is vague about arguments.


what i am looking for is a function that looks at one of these random variables and can move the reader 'head' to the exact file line specified by the random variable



say i wanted to load rabbit:

function_name(1) #since rabbit is the first line of foo.txt


is there a function like this?

if not, how do i replicate a function like this to put inside my game? not in terms of parameters etc. just what combination of function calls and loops etc do i need?  



thanks a million


edit: it is python

Edited by game of thought, 28 February 2013 - 02:34 PM.

#2   Members   


Posted 28 February 2013 - 02:21 PM

you would need to find or create a file reader/manager.  and then use it to sort out how to read the text file.  I found a simple one going through a tutorial on youtube.  its the platformer mad easy of c#.  its done by the guy from the site codingmadeeasy.com.  just check out the filemanager portion of his platformer tutorial.  


it reads in a file and goes through it till it finds the correct identifier, in your case monster name.  Then you can have multiple monsters on one file and load the correct one based on the programs need.  it is simple to set up and easy to use.  there are others already made for you out there that use other file formats, such as xml.  but they seem a little complicated for what you seem to be looking for.

#3   Members   


Posted 28 February 2013 - 02:44 PM

You can store these things in json file ("example.json"):


	"monsters": [
			"name": "Rabbit",
			"hp": 30,
			"attack": 5
			"name": "Rat",
			"hp": 40,
			"attack": 10


And load using python JSON library (included in Python 2.6):


import json

config_file = open('example.json')
data = json.load(config_file)

for monster in data["monsters"]:
    print monster

Edited by Nercury, 28 February 2013 - 02:45 PM.

#4   GDNet+   


Posted 28 February 2013 - 03:00 PM

you could also use an xml parser such as tinyXML, this would give you a bit more control/information to someone editing a text file, for example, you might do:


<Monster name="Rabbit">
 <Attribute Name="Hp" Value="10"/>


then all you have to do is go through and look for all monsters tags, then read their child tags to get information about the monster.

Edited by slicer4ever, 28 February 2013 - 03:01 PM.

Check out https://www.facebook.com/LiquidGames for some great games made by me on the Playstation Mobile market.

#5   Members   


Posted 28 February 2013 - 03:02 PM

thanks for the info, i will try it

#6   Members   


Posted 01 March 2013 - 11:04 AM

You can also use the ini format and use the python build-in module called config parser.

Here is the Doc: http://docs.python.org/2/library/configparser.html


Your file format would be:



hp = 30
attack = 5
attack_succeeded = "bites %s "
attack_failed = "bite %s"

hp = 40
attack = 10
attack_succeeded = "nibbles %s"
attack_failed = "nibble %s"

Currently working on a scene editor for ORX (http://orx-project.org), using kivy (http://kivy.org).

#7   Members   


Posted 01 March 2013 - 06:19 PM

When I started on my latest RPG, I got away from storing character definitions in a solid binary format that required me to build a separate editor. At first, I went text-base for quick-and-easiness, but eventually, I went with XML to store my enemy definition data. I used this approach to store battle configs for random battles encountered for that map too: assuming the battle config file was loaded and each enemy has an internal name to refer to it, you could create an element like <config>...</config> for each random battle enemy config, and provide an <enemy name="small_goblin"/>, or something like that.

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.