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

Place to get help with not working mods / modding interface.
Post Reply
kendoctor
Inserter
Inserter
Posts: 34
Joined: Wed Aug 05, 2020 6:43 pm
Contact:

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

Post 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

User avatar
DaveMcW
Smart Inserter
Smart Inserter
Posts: 3700
Joined: Tue May 13, 2014 11:06 am
Contact:

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

Post 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

kendoctor
Inserter
Inserter
Posts: 34
Joined: Wed Aug 05, 2020 6:43 pm
Contact:

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

Post by kendoctor »

thx, actually , i want a proerty of entity to store this data.

mrvn
Smart Inserter
Smart Inserter
Posts: 5709
Joined: Mon Sep 05, 2016 9:10 am
Contact:

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

Post 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.

kendoctor
Inserter
Inserter
Posts: 34
Joined: Wed Aug 05, 2020 6:43 pm
Contact:

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

Post 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

Post Reply

Return to “Modding help”