scripts load from world
[Tsunagari.git] / src / babysfirst / postMove.lua
blob518659a208f2b7fa36cfb2d227b0076d30811796
1 --
2 -- This script is executed every time an Entity finishes walking onto a tile.
3 --
4 -- We are called from within Entity::postMove() in entity.cpp. There, we are
5 -- passed some game data. We pass three variables to this script from the
6 -- Entity object: x, y, and entity, which represents the Entity itself.
7 --
8 -- We also have a C function we can call, gotoRandomTile, which takes an Entity
9 -- object as a parameter.
12 -- Returns true if we are standing on the specified X,Y location.
13 function on(X, Y)
14 return x == X and y == Y
15 end
17 -- Returns true if we are standing on any of the specified locations.
18 function onAny(locations)
19 for _,loc in ipairs(locations) do
20 if on(loc.x, loc.y) then
21 return true
22 end
23 end
24 return false
25 end
27 local redPortalLocations = {
28 {x = 11, y = 4},
29 {x = 4, y = 11}
32 -- The red portals teleport us! *gasp* Excitement!
33 if onAny(redPortalLocations) then
34 print("Lua says: Teleported!")
35 entity:gotoRandomTile()
36 end