Newbie Python (Game) Programming Question

Reynard T. Fox jwhinfinity at yahoo.com
Wed Mar 17 00:57:53 EST 2004


Tina <bad_addy at no_domain.com> wrote in message news:<VAJ5c.24601$%06.18480 at newsread2.news.pas.earthlink.net>...
> Hi,
> 
> I was wondering if there is a way to insert dynamic program code as data.
> For some reason I'm thinking Python does this. But I may be confused with
> another language or the article itself. I do think I could do this calling
> Python thru C, but that seems a bit clunky.
> 
> I'm including some of my code to learn stuff as well in case there's a
> better way to do things then how I currently am.
> 
> The program is a simple RPG character creator. (In this case from the
> Stormbringer 4th Ed RPG) In this, each character has a nation they hail
> from with attribute modifiers. These mods are listed under each nation as:
> 
> d100 to determine nation, nation name, 
> [att # to mod, # of dice, die type, final static bonus]
> 
> The problem is there's a bunch of "what if's" that are comming up. Not only
> for the nation list, but especially the character background list which is
> different for most nations and based on different attributes mixed with
> rolls. My initial thought is to include this list as a sub-list within the
> main nation list.
> 
> One "what if" is for Myrrhyn women to have +1d6 CHA. Now I could put this in
> the main code but I'm trying to make the basic generator as generic as
> possible for re-use.
> 
> Any help is appreciated!
> 
> Tina
> 

The design I'm implementing for my game(which is going to be a 2d
action game) is to write entire gameplay classes independently of the
main code, pack them into pickle files, then load the pickles into a
list, which is then referenced by the map I'm working on. The map
files, in turn, contain positions and references and a list of class
pickles to load, so that when the map is first loaded, there are
meta-objects in the corresponding positions that can be passed
arbitrary parameters to generate the ones actually wanted, and mods
can be created by simply recompiling the pickled classes or making new
ones for new maps. By giving all the classes common methods, I can
ensure that they work within the engine framework.

I've got it mostly done now: I can take a class from within the same
module and generate an arbitrary instance of it off of a pre-existing
meta. I just have to add the external functionality.

My system covers a lot more than what you need for your project, but
some of the same ideas can apply: You could make functions for every
nation's modifiers, and then load them into a list. The only tricky
part, then, comes in figuring out a way to make referencing the
nations modular, too. This is sort of the way I might do it:

diebounds = 0, 100
dielimits = [25, 50, 75, 100] # at each limit you have a different
nation
nationlist = [one(), two(), three(), four()]

(...we get a die roll)

increment=0

for x in dielimits:
    if roll<=x:
        nationlist



More information about the Python-list mailing list