Hey guys, apologies in advance if these have been answered before. I did search the forum, and some of these topics have been discussed briefly in the past, but I wasn’t able to find the answers I was looking for.
1. Using go.get()
instead of go.get_position()
If I understand correctly, the following has some performance implications since it needs to allocate a new vector3
object.
pos = go.get_position(".")
So do I understand correctly that the following would be faster?
pos_x = go.get(".", "position.x")
pos_y = go.get(".", "position.y")
Ditto for using go.set()
, instead of go.set_position()
.
2. Storing non-property objects on self
?
Suppose I want to store data on a script that don’t qualify to be Defold properties (e.g lists, strings, tables).
So far what I’ve been doing is something like the following:
go.property("health", 100)
function init(self)
self.some_list = [ ... ]
self.some_string = "hello world"
end
Sure I can’t access these custom properties using go.set()
or go.get()
, but I can access them from the other callbacks in the script and that’s fine for me.
Is this something that would hinder performance in the long-term?
If yes, how would you recommend to do it instead?
3. Accessing properties through self
or through the API
Performance-wise, is there any difference between the following two approaches?
health = self.health
self.health = health + 10
health = go.get('#', 'health')
go.set('#', 'health', health + 10)
(assume for simplicity that I have pre-hashed the #
and health
strings)