1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-06-27 16:36:03 +00:00

Scripting: Allow multiple global step callbacks and improve documentation

This commit is contained in:
Perttu Ahola 2011-11-12 19:19:58 +02:00
parent 7b802c547d
commit f8c9b70379
2 changed files with 89 additions and 15 deletions

View file

@ -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, {