Advertisement

Object States

Started by January 04, 2012 05:46 PM
0 comments, last by WitchLord 12 years, 10 months ago
One thing I liked about Unreal Script is that it included within the language a nice clean mechanism for states in objects.

class Mutilator extends Object;

state Ravage
{
function Attack()
{
// do something horrible and barbaric.
}
}

state Weakened
{
function Attack()
{
// do something horrible and barbaric, only weakened.
}
}


This is a criminally simple example, but you can see what I am getting at. What would I want to look at to implement something like this for Angelscript?
Rantings, ravings, and occasional insight from your typical code-monkey: http://angryprogrammingprimate.blogspot.com/
states is an interesting feature, but I don't see how to implement it as a built-in feature in the language without impacting everyone that don't need or want to use it.

The object would need to keep the actual state in some property. Then all the class method calls needs to be routed to the proper implementation through some lookup, similarly to how virtual methods have been implemented in AS.

Without it being a built-in feature you can probably make it work quite well by using pre-fixes, e.g:



class Mutilator : Object
{
function Ravage_Attack()
{
// do something horrible and barbaric.
}

function Weakened_Attack()
{
// do something horrible and barbaric, only weakened.
}
}


When the application calls the methods it can route the call to the correct implementation based on the state it keeps somewhere.

Of course, this won't work when the script calls the methods itself.

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

This topic is closed to new replies.

Advertisement