Zhanghua
Member
Is there any way to register "GET/SET function" pair for object's member variable?
I implement this as following, but think that isn't efficient and is ugly...., cause the Syntax isn't closure.
I implement this as following, but think that isn't efficient and is ugly...., cause the Syntax isn't closure.
GML:
//Global Script
function ObjMakeVariable(obj,name,val){
with(obj){
var env = { scope: id, name: name };
variable_instance_set(id,name,val);
variable_instance_set(id,"get"+name,method(env,function(){
return variable_instance_get(scope,name);
}));
variable_instance_set(id,"set"+name,method(env,function(v){
variable_instance_set(scope,name,v);
}));
}
}
//You can utilize this in the Object create event like this
ObjMakeVariable(id,"abc",1);
setabc(123);
show_message( getabc() );