Page 1 of 1

Could I associate extra data or private data for an entity object

Posted: Sat Aug 08, 2020 9:45 pm
by kendoctor
For example, if e is LuaEntity object
i want to bind some data to e using like this : e.extra_data = my_private_data
when i regain this object in another place, i can return the private data : local my_private_data = e.extra_data

Re: Could I associate extra data or private data for an entity object

Posted: Sat Aug 08, 2020 10:13 pm
by DaveMcW
Use the global object and the unit_number as the key.

Code: Select all

script.on_init(function()
  global.extra_data = {}
end)

function set_data(e, my_private_data)
  global.extra_data[e.unit_number] = my_private_data
end

function get_data(e)
  return global.extra_data[e.unit_number]
end

Re: Could I associate extra data or private data for an entity object

Posted: Sun Aug 09, 2020 11:37 am
by kendoctor
thx, actually , i want a proerty of entity to store this data.

Re: Could I associate extra data or private data for an entity object

Posted: Wed Aug 12, 2020 1:06 pm
by mrvn
kendoctor wrote: Sun Aug 09, 2020 11:37 am thx, actually , i want a proerty of entity to store this data.
Can't. That wouldn't be stored in save games and therefore lost when you load it again.

Re: Could I associate extra data or private data for an entity object

Posted: Wed Aug 12, 2020 1:47 pm
by kendoctor
mrvn wrote: Wed Aug 12, 2020 1:06 pm
kendoctor wrote: Sun Aug 09, 2020 11:37 am thx, actually , i want a proerty of entity to store this data.
Can't. That wouldn't be stored in save games and therefore lost when you load it again.
thx your reply. In old vb programs, mcrosoft using this tech for vb objects to store private data. That's why i ask this question