Scripted entities

:!: This document is a draft! It's not complete!

In this tutorial we explain a few mechanisms of yake::ent and illustrate them using the Lua based scripting plugin.

Events

Built-in

The following is a list of built-in events which are integral to yake::ent:

  1. onSpawn
  2. onDestroy

Working with custom events

Creating a custom event

Lua

In this example we create a custom event “TimeToDie” in the “onSpawned” event handler. This event callback is called right after the entity has been created and initialised.

events = {
  onSpawned = function()
  {
    theEntity:createEvent("TimeToDie");
  }
}

Firing a custom event

Lua:

Let's fire the event in Lua:

  theEntity:fireEvent("TimeToDie");

This instruction can be used in any event handler or other Lua function in entity scripts.

Reacting to a custom event from native C++ and Lua

Lua:

events = {
  onTimeToDie = function()
  {
    console.outLn("Dying...");
  }
}

C++:

// Using signals:
// CODE TO COME
 
// Using derived callback object:
// CODE TO COME

States

Working with custom states

Client / server events and states

States and some events are synchronized between servers and clients. The actual entity code between server and client may differ.

Reacting to client or server events

Use the same Lua code for clients and server:

events = {
  onSpawn = function() {
  }
}

Seperate code for clients:

events = {
  client = {
    onSpawn = function() {
    }
  }
}

DESCRIPTION TO COME.

 
tutorials/ent/scripted.txt · Last modified: 2008/02/21 21:59 (external edit)
 
Recent changes RSS feed Creative Commons License Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki