Hi, I would like to change self properties from gameobjects with the same script, from other script, I have the ID of the gameobject but don’t know how to access to that self properties or how to change the values.
-- why dont work this?
temp_self = go.get(my_id_from_other_script, self)
We have a way to have the self of the gameobject, or all the gameobject like this?
go.gameobject(id).self.my_property
Or how to access a specific gameobject data.
function init(self)
self.this = self
end
-- but how can acces to this?
Another option is to just used a shared module to access/modify another script’s self. For most purposes you can simply treat “self” as a table. This approach also lets you share/modify data types that can’t be object properties (notably tables), and is a lot faster than using go.get and go.set.
shared_data module (just an empty table):
return {}
script whose “self” you want access to:
local shared_data = require "path.to.shared_data"
function init(self)
self.instance_id = go.get_id()
shared_data[self.instance_id] = self
end
function final(self)
shared_data[self.instance_id] = nil
end
script you want to access another “self” in:
local shared_data = require "path.to.shared_data"
local function do_something_with_other_self(other_id)
local other_self = shared_data[other_id]
if other_self then
-- do whatever
end
end
I thought that go.property(“my_property”, value) was only to show the property on the shelf, so I just add in the init() self.start_position = go.get_position() without the go.property("start_position ", 0) so that was by bad, thanks for all your answers!.