Best python way to do 'object messaging'
Philip Swartzleonard
starx at pacbell.net
Fri Feb 8 21:11:54 EST 2002
Ok, so i have this pre-prototype (embrionic? :) game system, rogueish,
that basically involves a bunch of different objects running around a
map, containing each other, beating each other up, that kind of thing
:). What i'm trying to do is set up a general purpouse system for
passing messages between the interface, the objects, the AI's, the game
world and timing system, and whatever else comes up. Here are my current
ideas/contarints:
1. Basic interface: anything that can accept a message has a .message
(msg) function attaced to it. If the player hits a critter, some part of
the player (i have the body and control seperated) sends the body of the
critter a damage/type/amount/source type message.
2. It has to be able to be passed easily through various receptor
objects that don't really care about what the message is. For example, i
do something along the lines of 'map.messageradius(
msg,x,y,radius,inv_arsqrd(1.2) ), which only affects a 'percentage of
effect' segment of the message while distrubiting it to all of the
affected cells, which do nothing but ditrubite it to whatever objects or
creatures happen to be standing there.
3. It has to be storable. My idea for a global timekeeping system is
something that stores messages to send to objects at various times. For
example, an AI object would always set a ai-tick message to itself at
some time in the future at the end of its run, and this is the way that
I would get keep 'live' objects updated properly.
I am currently thinking of representing the message as an object with
various properties, and having each object that recieves one switch on
the type of message, or even better, have a routine in a base class that
takes some element of the message object, does a little string mangling,
and calls a 'Rec<MESSAGETYPE>(message)' function similar to how TADS
uses the VerDoXXX, VerIoXXXWith kind of functions for dealing with verbs
(if anyone knows enough about TADS to understand this analogy ... it's
one of my favorite languages :).
This is -probably- what i'm going to go with, but i'd like to see if
anyone has any ideas/comments/insperations/pointers-to-relevant-
information, because i've never really made a system like this in any
language, and i'd like to get it right before i build most of the rest
of the system over it (i alredy have to refactor(i think that's how you
use it) all of my display stuff out of the game data stuff, and remake
the resource system -again- :)
Thanks for anything :)
--
Philip Sw "Starweaver" [rasx] :: www.rubydragon.com
More information about the Python-list
mailing list