Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


Don't forget to read Tuesday's email newsletter for your chance to win a free copy of Construct 2!


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 game of thought   Members   -  Reputation: 213

Like
0Likes
Like

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

 

Rabbit

30#hp

5#attack

bites #success verb

bite #fail verb 

 

rat

40

10

nibbles

nibble

 

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

 

e.g.

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.


Sponsor:

#2 moneal2001   Members   -  Reputation: 607

Like
0Likes
Like

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 Nercury   Crossbones+   -  Reputation: 770

Like
2Likes
Like

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)
config_file.close()

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

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


#4 slicer4ever   Crossbones+   -  Reputation: 3947

Like
2Likes
Like

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"/>
 ...
</Monster>
...

 

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 game of thought   Members   -  Reputation: 213

Like
0Likes
Like

Posted 28 February 2013 - 03:02 PM

thanks for the info, i will try it



#6 KnolanCross   Members   -  Reputation: 1334

Like
1Likes
Like

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:

 

 

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

[Rat]
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 Vincent_M   Members   -  Reputation: 715

Like
0Likes
Like

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.



PARTNERS