I was looking for a neat way of defining things once for each object or even globally... BUT something that could be done from inside the object itself (maybe create event).
some of the ideas I came up with:
PROS: Neat and clean.
CONS: The function `getSharedData` is defined for all instances and it occupies memory unnecessarily.
PROS: Nothing is redeclared or occupies extra memory.
CONS: Not so clean.
I wanted something that could allow for
I know this could be easily done with scripts. Put the declaration in a script file inside a function and do something like the first example... but I was looking to maintain everything related to an object somewhere inside the object itself. So this is more of a project management issue.
I would love to hear your ideas!
some of the ideas I came up with:
GML:
getSharedData = function() {
static data = undefined;
if (data != undefined) return data;
// define instance
return data;
}
sharedData = getSharedData();
CONS: The function `getSharedData` is defined for all instances and it occupies memory unnecessarily.
GML:
if (!variable_global_exists(object_get_name(object_index))) {
var data;
// define instance
variable_global_set(object_get_name(object_index), data);
}
sharedData = variable_global_get(object_get_name(object_index));
CONS: Not so clean.
I wanted something that could allow for
defineOnce
and defineOnceGlobal
, the first one would defined for the given object and the latter would define on a global scope.I know this could be easily done with scripts. Put the declaration in a script file inside a function and do something like the first example... but I was looking to maintain everything related to an object somewhere inside the object itself. So this is more of a project management issue.
I would love to hear your ideas!