Pages

Thursday, June 3, 2010

Action Script Modes

I wrote a few strange little scripts today that ultimately resulted in a creature's ability to randomly tint everything it pushes, just for fun. Kinda useless, but the scripting behind it might not be.

I've had this idea in my head for a while of the ability to switch the game into different "modes" when needed, modes that basically affect everything in the world and how it works. Creature action scripts, to be specific.

Creature action scripts (I don't know if that's the proper name for them but it's what I call them anyway) are the default scripts that define what happens when a creature does something or when something is done to a creature. You can find these in your bootstrap folder in files like "DS creatureDecisions.cos" and "DS creatureToCreature.cos." These are the scripts I modify to make my Critical Hit or Interspecies Breeding scripts.

What I set out to do today was to essentially create an easy way to shift between different sets of action scripts, between the default push/pull/eat/hit/mate/etc scripts and my custom ones, without having to reinject them every time (which often results in errors if there are creatures making use of those scripts).

It worked basically by making a "state" agent who's purpose was to act as a switch between the default scripts and the altered scripts. Then at the beginning of the default push script, I added a bit of code that basically said "check the state agent to see what to do." When the state agent is in the default state, it will tell the script to go ahead and run the script as usual, but if it is set to another state with a mesg wrt+ command, it will run an alternate script instead (or if the alternate script isn't there, the default script again).

To do this, the "state" is set to a number, 0 for default, and something like 1000 for alternates. If the push script is activated (script 17) and the state is set to an alternate of 1000, the script will add its number to the state number, thus running 1017 instead. But first it checks to make sure 1017 exists-- if it doesn't, it'll run script 17 anyway. So I can make a set of modified scripts one script at a time and not worry about errors being thrown if it's not a complete set.

I'm really not sure if there's a decent purpose for this system outside of development and testing, but it's an interesting little system. Possibly it could be used to switch easily between "easy mode" and "hard mode" sets of scripts-- right now I'm using it to switch between scripts that stim writ the creature and those that don't to try and find a way to teach creatures regardless of genetics.

Coming soon (hopefully): Population Control Tools!

No comments:

Post a Comment