aboutsummaryrefslogtreecommitdiff
path: root/data
diff options
context:
space:
mode:
authorPerttu Ahola <celeron55@gmail.com>2011-11-12 19:19:58 +0200
committerPerttu Ahola <celeron55@gmail.com>2011-11-29 19:13:40 +0200
commitf8c9b703798873c6e958560341105069dca8f86c (patch)
treed39e85cc36b957c372cfbab7ffc1252faaea16ab /data
parent7b802c547dc23b022605bc7b934c31461b47622b (diff)
downloadminetest-f8c9b703798873c6e958560341105069dca8f86c.tar.gz
minetest-f8c9b703798873c6e958560341105069dca8f86c.tar.bz2
minetest-f8c9b703798873c6e958560341105069dca8f86c.zip
Scripting: Allow multiple global step callbacks and improve documentation
Diffstat (limited to 'data')
-rw-r--r--data/scripts/default.lua52
1 files changed, 43 insertions, 9 deletions
diff --git a/data/scripts/default.lua b/data/scripts/default.lua
index 0b9f8b913..eda7cd25e 100644
--- a/data/scripts/default.lua
+++ b/data/scripts/default.lua
@@ -72,13 +72,47 @@ function dump(o, dumped)
end
end
+-- Global functions:
+-- minetest.register_entity(name, prototype_table)
+-- minetest.register_globalstep(func)
+--
+-- Global objects:
+-- minetest.env - environment reference
+--
+-- Global tables:
+-- minetest.registered_entities
+-- ^ List of registered entity prototypes, indexed by name
+-- minetest.object_refs
+-- ^ List of object references, indexed by active object id
+-- minetest.luaentities
+-- ^ List of lua entities, indexed by active object id
+--
+-- EnvRef methods:
+-- - add_node(pos, content); pos={x=num, y=num, z=num}
+--
+-- ObjectRef methods:
+-- - remove(): remove object (after returning from Lua)
+-- - getpos(): returns {x=num, y=num, z=num}
+-- - setpos(pos); pos={x=num, y=num, z=num}
+-- - moveto(pos, continuous=false): interpolated move
+-- - add_to_inventory(itemstring): add an item to object inventory
+--
+-- Registered entities:
+-- - Functions receive a "luaentity" as self:
+-- - It has the member .object, which is an ObjectRef pointing to the object
+-- - The original prototype stuff is visible directly via a metatable
+--
+
print("omg lol")
print("minetest dump: "..dump(minetest))
-- Global environment step function
function on_step(dtime)
+ -- print("on_step")
end
+minetest.register_globalstep(on_step)
+
local TNT = {
-- Maybe handle gravity and collision this way? dunno
physical = true,
@@ -112,6 +146,15 @@ function TNT:on_rightclick(clicker)
pos = {x=pos.x, y=pos.y+0.1, z=pos.z}
self.object:moveto(pos, false)
end
+
+print("TNT dump: "..dump(TNT))
+
+print("Registering TNT");
+minetest.register_entity("TNT", TNT)
+
+print("minetest.registered_entities:")
+dump2(minetest.registered_entities)
+
--[[
function TNT:on_rightclick(clicker)
print("TNT:on_rightclick()")
@@ -125,15 +168,6 @@ function TNT:on_rightclick(clicker)
end
--]]
-print("TNT dump: "..dump(TNT))
-
-print("Registering TNT");
-minetest.register_entity("TNT", TNT)
-
---print("minetest.registered_entities: "..dump(minetest.registered_entities))
-print("minetest.registered_entities:")
-dump2(minetest.registered_entities)
-
--[=[
register_block(0, {