[Solved] Custom entities' properties using the new method

User avatar
Hamlet
Member
 
Posts: 695
Joined: Sat Jul 29, 2017 21:09
Location: Lombardy, Italy
GitHub: h4ml3t
IRC: H4mlet

[Solved] Custom entities' properties using the new method

by Hamlet » Thu Dec 12, 2019 19:12

Accordingly to the lua_api.txt

Object properties being read directly from the entity definition
table is deprecated. Define object properties in this
`initial_properties` table instead.


I've tried adding a custom property, but it seems that is being ignored.
Example:

Code: Select all
initial_properties = {
   visual = 'mesh',
   mesh = 'my_mesh.b3d',
   my_custom_property = 'hello',
   etc.
}


Dumping the object's properties using print(dump(self.object:get_properties())) shows all the default properties, not the custom:

Code: Select all
2019-12-12 20:04:14: ACTION[Server]: singleplayer right-clicks object 2: LuaEntitySAO at (245,9,345)
{
   selectionbox = {
      -0.5,
      -0.5,
      -0.5,
      0.5,
      0.5,
      0.5
   },
   makes_footstep_sound = true,
   nametag = "",
   zoom_fov = 0,
   wield_item = "",
   hp_max = 20,
   static_save = false,
   infotext = "",
   visual_size = {
      y = 1,
      x = 1,
      z = 1
   },
   automatic_face_movement_max_rotation_per_sec = -1,
   weight = 50,
   nametag_color = {
      a = 255,
      b = 255,
      g = 255,
      r = 255
   },
   is_visible = true,
   mesh = "",
   glow = 0,
   textures = {
      "era_y_positive.png",
      "era_y_negative.png",
      "era_x_positive.png",
      "era_x_negative.png",
      "era_z_positive.png",
      "era_z_negative.png"
   },
   physical = true,
   stepheight = 1.1000000238419,
   collisionbox = {
      -0.5,
      -0.5,
      -0.5,
      0.5,
      0.5,
      0.5
   },
   initial_sprite_basepos = {
      y = 0,
      x = 0
   },
   backface_culling = true,
   collide_with_objects = true,
   pointable = true,
   use_texture_alpha = false,
   eye_height = 1.625,
   colors = {
      {
         a = 255,
         b = 255,
         g = 255,
         r = 255
      }
   },
   automatic_rotate = 0,
   visual = "cube",
   automatic_face_movement_dir = 0,
   breath_max = 11,
   spritediv = {
      y = 1,
      x = 1
   }
}


By the way, 'hp_max', 'breath_max', 'zoom_fov' and 'eye_height' are being listed even if in the lua_api.txt they are marked as 'for players only'.
Last edited by Hamlet on Sat Dec 14, 2019 13:17, edited 1 time in total.
 

User avatar
rubenwardy
Moderator
 
Posts: 5938
Joined: Tue Jun 12, 2012 18:11
Location: United Kingdom
GitHub: rubenwardy
IRC: rubenwardy
In-game: rubenwardy

Re: Defining custom entities' properties using the new metho

by rubenwardy » Sat Dec 14, 2019 02:01

Custom object properties aren't supported because that doesn't make sense - properties are to communicate things like rendering settings and such with the client, not for arbitrary storage

You should store custom values in the entity table directly. The modding book has a chapter to explain this https://rubenwardy.com/minetest_modding_book/en/map/objects.html#entities
 

User avatar
texmex
Member
 
Posts: 1661
Joined: Mon Jul 11, 2016 21:08
GitHub: tacotexmex
In-game: texmex

Re: Defining custom entities' properties using the new metho

by texmex » Sat Dec 14, 2019 08:19

Oh, I remember this problem. It almost drove me nuts. If only I could remember the solution. It was something about adding the properties on entity spawn instead of at initialization.
 

User avatar
Hamlet
Member
 
Posts: 695
Joined: Sat Jul 29, 2017 21:09
Location: Lombardy, Italy
GitHub: h4ml3t
IRC: H4mlet

Re: Defining custom entities' properties using the new metho

by Hamlet » Sat Dec 14, 2019 13:01

rubenwardy wrote:Custom object properties aren't supported because that doesn't make sense - properties are to communicate things like rendering settings and such with the client, not for arbitrary storage

You should store custom values in the entity table directly. The modding book has a chapter to explain this https://rubenwardy.com/minetest_modding_book/en/map/objects.html#entities


Ah! Now I understand: reading that warning I thought that *any* property had to be defined there, for example 'custom_time_to_live'.
Instead only *default* properties are to be set in the initial_properties table, while *custom properties* are to be placed in the entity's definition table as usual.

Thanks for the clarification and for the link to the relative MMB's chapter, I'm going to read it thoroughly.
 

User avatar
Hamlet
Member
 
Posts: 695
Joined: Sat Jul 29, 2017 21:09
Location: Lombardy, Italy
GitHub: h4ml3t
IRC: H4mlet

Re: Defining custom entities' properties using the new metho

by Hamlet » Sat Dec 14, 2019 13:14

texmex wrote:Oh, I remember this problem. It almost drove me nuts. If only I could remember the solution. It was something about adding the properties on entity spawn instead of at initialization.


Same here, I was headdesking trying to understand why it wasn't working.

It's just a matter of wording, instead of writing:
Object properties being read directly from the entity definition
table is deprecated. Define object properties in this
`initial_properties` table instead.


one could write:
'Default object properties being read directly from the entity definition table is deprecated.
Define these properties in this `initial_properties` table instead.
Define custom object values - e.g. 'mob_name' - in the entity table directly.'

In my opinion, but that's just me: perhaps I'm the only one having misunderstood.
 

User avatar
rubenwardy
Moderator
 
Posts: 5938
Joined: Tue Jun 12, 2012 18:11
Location: United Kingdom
GitHub: rubenwardy
IRC: rubenwardy
In-game: rubenwardy

Re: [Solved] Custom entities' properties using the new metho

by rubenwardy » Sat Dec 14, 2019 13:29

"object properties" has a specific but misleading definition, and should probably be renamed, but I have no idea what to. Object properties are stored in C++ and sent to the client
 

User avatar
Hamlet
Member
 
Posts: 695
Joined: Sat Jul 29, 2017 21:09
Location: Lombardy, Italy
GitHub: h4ml3t
IRC: H4mlet

Re: [Solved] Custom entities' properties using the new metho

by Hamlet » Sat Dec 14, 2019 17:48

rubenwardy wrote:"object properties" has a specific but misleading definition, and should probably be renamed, but I have no idea what to. Object properties are stored in C++ and sent to the client


I think that just using the 'default' and 'custom' terms would be enough: the tech-savvy would understand the underlying difference (C++ related) while the others would know that exist 'reserved' properties - to be put in the initial_properties table - and 'user defined' properties, to be placed out of that table.
 


Return to Problems



Who is online

Users browsing this forum: No registered users and 1 guest