Created
January 29, 2017 13:29
-
-
Save LukeMS/5e6bc467a420ee2cc7544f690c3c4fae to your computer and use it in GitHub Desktop.
Example for an added feature on beholder.lua (event can be stopped from propagating further on)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
beholder = require("beholder") | |
print("stopObserving: callback is permanently removed") | |
function observer1() | |
local id | |
id = beholder.observe( | |
'PLAYERDETECTION', | |
function(x, y) | |
print("observer1: player1 detected at", x, y) | |
if x >= 5 then | |
beholder.stopObserving(id) | |
end | |
end | |
) | |
end | |
function observer2() | |
local id | |
id = beholder.observe( | |
'PLAYERDETECTION', | |
function(x, y) | |
print("observer2: player1 detected at", x, y) | |
if x >= 8 then | |
beholder.stopObserving(id) | |
end | |
end | |
) | |
end | |
observer1() | |
observer2() | |
for i = 1, 10 do | |
beholder.trigger('PLAYERDETECTION', i, 200) | |
end | |
print("-----") | |
for i = 1, 10 do | |
beholder.trigger('PLAYERDETECTION', i, 200) | |
end | |
beholder.reset() | |
print("\n##################\n") | |
print("stopPropagation: callback won't propagating *this* event further") | |
print("stopPropagation") | |
function observer1() | |
local id | |
id = beholder.observe( | |
'PLAYERDETECTION', | |
function(x, y) | |
print("observer1: player1 detected at", x, y) | |
if x >= 3 then | |
beholder.stopPropagation(id) | |
end | |
end | |
) | |
end | |
function observer2() | |
local id | |
id = beholder.observe( | |
'PLAYERDETECTION', | |
function(x, y) | |
print("observer2: player1 detected at", x, y) | |
if x >= 3 then | |
beholder.stopPropagation(id) | |
end | |
end | |
) | |
end | |
observer1() | |
observer2() | |
for i = 1, 10 do | |
beholder.trigger('PLAYERDETECTION', i, 200) | |
end | |
print("-----") | |
for i = 1, 10 do | |
beholder.trigger('PLAYERDETECTION', i, 200) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment