Quote:Original post by The Reindeer Effect
Just out of curiosity, what are your current plans for how to implement this?
I'm looking at two methods; one's going to be a simple command-style language that again will be loaded as a list of actions that can be 'triggered' by a user-definable event.
The other way I'm going to look at it is to use a real scripting language instead (probably GameMonkey Script or SpiderMonkey). Think of how javascript is added to HTML "onClick" events are declared, or some kind of .NET delegate. I'll have a section in the XML that allows the user to define their own events and provide a script method to call; each script method should have automatically pass a 'sender' and a 'trigger'.
Note that all scripting is in GameMonkey script for this pseudoexample.
<entityClass id="Door"> <entityEvent name="Open" call="door_OnOpened(this, trigger);" /> <entityAttrib name="isOpen" type="bool" value="false" /></entityClass><entityInstance class="Door" id="NormalDoor"> <!-- When object tries to 'Open' the door, the normal script is called --></entityInstance><entityInstance class="Door" id="BigDoor"> <entityEvent overrides="Open" call="bigdoor_OnOpened(this, trigger);" /></entityInstance>//// Then some script...door_OnOpened = function( this, triggerBy ){ this.isOpen = true; return true;};bigdoor_OnOpened = function( this, triggerBy ){ if triggerBy.strength < someArbitraryValue { this.isOpen = true; return true; } // else gameMessage( "Not strong enough to open the door!" ); return false;};
Here I'm likely to make scripting work like HTML/javascript eg: each 'call' will effectively be a mini-script that will have the 'this' and 'triggerBy' objects made available to the sandbox. Notice that here, in script, I can use the attributes as they normally appear. This could be done in real-time when checking for the attribute using GameMonkey script (because it's cool [wink])<br><br><br><br>Thinking in the dynamic/data-driven mindset, my native methods for events won't be normal method calls, they'll be events that need to be registered with the entity. Sure, these events will call native functions, but that's not the point. What I'm going to do to my current message/event system is allow an entity to keep a list of <b>overrides</b> for a given event. If an event is marked as overriden, a special (native) method will be called to pass the relevant parameters to the script and call the scripted function.<br><br>So, I could potentially hardcode a generic spaceship entity class but override the <tt>OnThink</tt> method with a scripted method to give it some unique kamikaze behaviour [wink].<br><br>Like I said, this is currently WIP and so have no idea about how effctive it'll be... But if it works it could really make things really cool in my games... And anyone else who'll want it too as I release most of my stuff as open-source.<br><br>Edit: <br><br>I forgot to add; each entity will have a native method to allow it access to the scripted functions. Something like <tt>Entity::CallMethod("name", this, that)</tt> - this then opens up the scripted overrides to the programmer who wants to work totally in script for things like AI, etc.<br><br><!--EDIT--><span class=editedby><!--/EDIT-->[Edited by - evolutional on February 10, 2005 2:37:56 PM]<!--EDIT--></span><!--/EDIT-->