initial_properties field in entity definition
authorPerttu Ahola <celeron55@gmail.com>
Sat, 31 Mar 2012 10:50:25 +0000 (13:50 +0300)
committerPerttu Ahola <celeron55@gmail.com>
Sat, 31 Mar 2012 10:50:25 +0000 (13:50 +0300)
doc/lua_api.txt
games/minimal/mods/experimental/init.lua
src/scriptapi.cpp

index db8ae25b1c133d1f01773c9030fb71ee4a4842c6..b068a8a019f77044c14298c6f423cf6dd94a5fdc 100644 (file)
@@ -792,8 +792,10 @@ Object Properties
 
 Entity definition (register_entity)
 {
-    Everything from object properties,
-    -- entity specific --
+    (Deprecated: Everything in object properties is read directly from here)
+    
+    initial_properties = <initial object properties>,
+
     on_activate = function(self, staticdata),
     on_step = function(self, dtime),
     on_punch = function(self, hitter),
@@ -801,6 +803,7 @@ Entity definition (register_entity)
     get_staticdata = function(self),
     ^ Called sometimes; the string returned is passed to on_activate when
       the entity is re-activated from static state
+    
     # Also you can define arbitrary member variables here
     myvariable = whatever,
 }
index 55ea64132ef98405ac568111b787bc034259172c..11f32b3f9cda8ab0084960f2205a72f28a57a0f3 100644 (file)
@@ -409,16 +409,17 @@ minetest.register_alias("TNT", "experimental:tnt")
 --
 
 minetest.register_entity("experimental:dummyball", {
-       -- Static definition
-       hp_max = 20,
-       physical = false,
-       collisionbox = {-0.4,-0.4,-0.4, 0.4,0.4,0.4},
-       visual = "sprite",
-       visual_size = {x=1, y=1},
-       textures = {"experimental_dummyball.png"},
-       spritediv = {x=1, y=3},
-       initial_sprite_basepos = {x=0, y=0},
-       -- Dynamic variables
+       initial_properties = {
+               hp_max = 20,
+               physical = false,
+               collisionbox = {-0.4,-0.4,-0.4, 0.4,0.4,0.4},
+               visual = "sprite",
+               visual_size = {x=1, y=1},
+               textures = {"experimental_dummyball.png"},
+               spritediv = {x=1, y=3},
+               initial_sprite_basepos = {x=0, y=0},
+       },
+
        phase = 0,
        phasetimer = 0,
 
index 4ca114a0cd37d57da4eaf64129ab2016a24b8b52..a9f54627d45834f09d17e76795216653582229f2 100644 (file)
@@ -4887,8 +4887,13 @@ void scriptapi_luaentity_get_properties(lua_State *L, u16 id,
        // Set default values that differ from ObjectProperties defaults
        prop->hp_max = 10;
        
-       // Read stuff
+       // Deprecated: read object properties directly
        read_object_properties(L, -1, prop);
+       
+       // Read initial_properties
+       lua_getfield(L, -1, "initial_properties");
+       read_object_properties(L, -1, prop);
+       lua_pop(L, 1);
 }
 
 void scriptapi_luaentity_step(lua_State *L, u16 id, float dtime)