News Board

Message Details

New Behaviours!

By Tristan on 02/06/2010 12:27:08

Greetings!

I have updated the server so that it is running the most recent code. The biggest change is to the npc brain and behaviour system, although there are many smaller changes throughout the rest of the code. This means that most of your npcs and code will not compile until you update it.

I have created a very simple example npc, the "example duck", to show how the new behaviours can be used. The code is visible on the website at http://http://www.antikaria.com/doc/TestLib.Examples/Duck.html. You can create a duck with "create TestLib.Examples.Duck".

When you are setting up an npc that is going to use behaviours, you need to call InitBrain() to set things up. Behaviours are implemented as classes that inherit from the base Behaviour class. The method Run() is overridden with whatever the behaviour is supposed to do. When a behaviour gets to the end of the Run() method, it repeats again from the top.

Behaviours each have a priority. The higher the priority, the more "important" the behaviour is. Behaviours can call "this.Begin()" to start exclusive mode and "this.End()" to finish. Only one behaviour can be running in exclusive mode at a time and this will be the behaviour that has the highest priority. Any behaviours with lower priority will not run at all when a higher behaviour is in exclusive mode. Any behaviours of equal or greater priority will still run. If a higher one then starts exclusive mode, the lower behaviour will stop until the higher one has finished.

This is a little complicated, but it is very flexible. The main idea is to have behaviours start and then simply wait for the right conditions or events before beginning exclusive mode and doing whatever the behaviour should do. In the example duck this is seen in the angry behaviour. It has a higher priority than the default behaviour, but does nothing until it is poked. When it is poked, it begins exclusive mode, and the default behaviour is paused until the angry behaviour ends exclusive mode. The angry behaviour then goes back to waiting.

There are quite a few functions called "WaitFor______()" These functions wait for an event to happen. There is another function called Sleep() that just waits for a certain amount of time. I'll write a more comprehensive guide at some point!

I'm sure there will be lots of questions, so please ask!

Tristan

Back to board index.