diff --git a/README.textile b/README.textile index eed8dcb..c6e6dcc 100644 --- a/README.textile +++ b/README.textile @@ -88,41 +88,41 @@ Events can be any type of Lua object. On the example, we used the "PAUSE" string Composed events are built from more than one lua object. You can do them by simply adding more parameters to the observe/trigger functions. For example, this trigger. -
Beholder.trigger('PLAYERDETECTION', player1, 100, 200)+
beholder.trigger('PLAYERDETECTION', player1, 100, 200)Will trigger this action. -
Beholder.observe('PLAYERDETECTION', player1, 100, 200, function() print("player1 detected at 100, 200") end)+
beholder.observe('PLAYERDETECTION', player1, 100, 200, function() print("player1 detected at 100, 200") end)Composed events are inclusive. This means that this other observer will also get activated by the aforementioned trigger. -
Beholder.observe('PLAYERDETECTION', player1, function(x,y) print("player1 detected at ",x,y)+
beholder.observe('PLAYERDETECTION', player1, function(x,y) print("player1 detected at ",x,y)Notice that the two "non-observed integers" will be passed to the callback as additional parameters. That second action will be executed any time player1 is detected, no matter what coordinates. Similarly, you can add an action that will be triggered for any player detection. -
Beholder.observe('PLAYERDETECTION', function(player,x,y) print(player.no," detected at ",x,y)+
beholder.observe('PLAYERDETECTION', function(player,x,y) print(player.no," detected at ",x,y)h1. The nil event If you want to detect all signals raised (i.e. for logging and debugging) you can do so by observing the "empty" event - simply pass a function to observe, without adding any more params. -
Beholder.observe(function(...) log("Event triggered", ...) end)+
beholder.observe(function(...) log("Event triggered", ...) end)A quick and dirty way of dumping all events in the standard output is just observing the nil event with @print@. -
Beholder.observe(print)+
beholder.observe(print)If you want to trigger the events attached only to the nil event, you can do so by calling trigger without params. -
Beholder.trigger()+
beholder.trigger()h1. Triggering all callbacks You can use the @triggerAll@ method to trigger all observed events (this will be useful mostly for debugging). -
Beholder.triggerAll(...)+
beholder.triggerAll(...)Note that you can pass parameters to @triggerAll@. These will be passed to all callbacks (make sure that they are prepared for this, or you will get errors). @@ -131,9 +131,9 @@ h1. Installation Just copy the beholder.lua file wherever you want it (for example on a lib/ folder). Then write this in any Lua file where you want to use it. -
local Beholder = require 'beholder'+
local beholder = require 'beholder'-On this example I've assigned it to a local variable. If you are going to use Beholder across multiple files, it's better to require the file just once and make the variable global. +On this example I've assigned it to a local variable. If you are going to use beholder across multiple files, it's better to require the file just once and make the variable global. The @package.path@ variable must be configured so that the folder in which beholder.lua is copied is available, of course.