Yes, you should take a look at the util/record.py file. An example for how to use it would be in things/terrain/terrainLoader.py. Basically you hand it the path to the file you want to load, and a function to call for each element in the JSON list in that file. It'll load the JSON structure, iterate over the elements in it, and call the given function for each one. In this case the function being called is a class constructor (the __init__() function in terrainFactory.py).
Programming Q&A
Collapse
X
-
One for the Dark Lord on his dark throne
In the Land of Mordor where the Shadows lie.Comment
-
So my question is, is it possible to read that stuff in from the file and then refer to stat[STR] in the code? Come to think of it, I wouldn't know how to do this in C either, but I'm actually interested in Python because I kind of have a hunch that Python can do this.
(Let's leave aside the question of why one would hard-code references to stats which are defined in an external file - one thing at a time!)
The harder problem is how to link stats defined in a file to what they modify in-game. I see two approaches:
1) is for things that can be altered by stats to specify what flags they're looking for. Stats then have or don't have such flags (and possibly other data associated with it, like constants/factors/thresholds).
2) is for stats to specify what things they alter. Whenever an alterable roll or number is computed in game it will first check to see if any stats specify they alter it, and using what formula (python has eval() for example, or you could roll your own syntax).
You'd also need to have some dynamically binding specification of how stats are rolled, what classes/races get what stats, etc. again using the system of your choice.My Chiptune music, made in Famitracker: http://soundcloud.com/patashuComment
-
You could define the stats in an XML formatted file - most languages will have an XML parser library by default, so you can serialize to and from such a format without writing any special code. The in-memory representation of such XML will be a hierarchical tree structure, or maybe you'd flatten it to dictionaries for example. You can ask this representation 'Do you have an entry called STR?' and if it does it returns you all the information stored under STR.
The harder problem is how to link stats defined in a file to what they modify in-game. I see two approaches:
1) is for things that can be altered by stats to specify what flags they're looking for. Stats then have or don't have such flags (and possibly other data associated with it, like constants/factors/thresholds).
2) is for stats to specify what things they alter. Whenever an alterable roll or number is computed in game it will first check to see if any stats specify they alter it, and using what formula (python has eval() for example, or you could roll your own syntax).
Number: 1
Name: Fireball
Range: 8 + stat[INT] / 5
Damage: clev * d6 * (100 + stat[WIS] / 2) / 100
Save: stat[CON] > 10 ? half : no
I guess this is not a million miles from your #1, without the need for stats to have flags."Been away so long I hardly knew the place, gee it's good to be back home" - The BeatlesComment
-
Effects can certainly have a lot of leeway in deciding how to use stats. However, I wouldn't try to stuff all interpretation of stats into effects. Some fundamental game rules, like how combat works or how to decide the failure rate on a spell, is going to go into the core engine. So any stats that deal with those "core rules" should just be assumed to exist (and filled in with defaults for the cases where the data files don't define them, e.g. for the majority of monsters).
The bottom line is that you have to strike a balance between flexibility and getting stuff done. A maximally-flexible game engine will be impossible to debug, and will likely never be finished, because of all the added complexity that introducing that flexibility causes. On the flipside, a game engine that hardcodes everything can get basic stuff done very quickly, but becomes horribly difficult to extend to get to a "finished game".Comment
-
I had a different thought about this, based on my earlier thinking about the effects framework. In my design, effects should specify how stats affect them, for example:
Number: 1
Name: Fireball
Range: 8 + stat[INT] / 5
Damage: clev * d6 * (100 + stat[WIS] / 2) / 100
Save: stat[CON] > 10 ? half : no
I guess this is not a million miles from your #1, without the need for stats to have flags.
Addendum: I also agree with Derakon. Customization is something you tack on because you know you'll need it anyway. So don't make a fully customizable game engine when all you need is a game.My Chiptune music, made in Famitracker: http://soundcloud.com/patashuComment
-
You could define the stats in an XML formatted file - most languages will have an XML parser library by default, so you can serialize to and from such a format without writing any special code. The in-memory representation of such XML will be a hierarchical tree structure, or maybe you'd flatten it to dictionaries for example. You can ask this representation 'Do you have an entry called STR?' and if it does it returns you all the information stored under STR.
XML is not good for data -- this should not be surprising given its origins. If you use it for marking up content (hardly anyone outside of office suites does it seems), it's a pretty reasonable format. If you use it for data format definition, however...
The data model is ridiculously complex, namespaces are overly complex, it's verbose, it's not actually human-readable/writable in practice... and 99%(*) of uses can be trivially replaced with s-exprs.
Also, AFAICT all current C libraries for XML suck (insanely verbose, no data binding, etc. etc.). S-exprs in C are dead simple using sexpr, and JSON is also dead simple using Jansson.
As things stand the only valid (technical) reason I can currently see for using XML would be data binding, but if you're using a language with dynamic type checking that is already of dubious value.
(*) Estimates may vary. No waranty. Void where prohibited. (etc.)Comment
-
I think you're making my point - I'd envisage you could do precisely that, by defining the effects which used WIL as a save instead of WIS."Been away so long I hardly knew the place, gee it's good to be back home" - The BeatlesComment
-
Effects can certainly have a lot of leeway in deciding how to use stats. However, I wouldn't try to stuff all interpretation of stats into effects. Some fundamental game rules, like how combat works or how to decide the failure rate on a spell, is going to go into the core engine. So any stats that deal with those "core rules" should just be assumed to exist (and filled in with defaults for the cases where the data files don't define them, e.g. for the majority of monsters).
The bottom line is that you have to strike a balance between flexibility and getting stuff done. A maximally-flexible game engine will be impossible to debug, and will likely never be finished, because of all the added complexity that introducing that flexibility causes. On the flipside, a game engine that hardcodes everything can get basic stuff done very quickly, but becomes horribly difficult to extend to get to a "finished game"."Been away so long I hardly knew the place, gee it's good to be back home" - The BeatlesComment
Comment