Well I suggested onVarChanged() along time ago myself.
By the way, you should call them variables instead of strings.
Also, I had thought it might be a better idea to be able to define a read and write function for a variable, easily making variables read only or private or be able to notify the object of changes.
Something like this:
PHP Code:
function onCreated() {
this.join("util_callstack");
this.strvar = 0; // initialize it (insurance)
this.strvar.setreadfunction(this.read_strvar);
this.strvar.setwritefunction(this.write_strvar);
}
// The actual value would be stored invisibly by GScript and only provided as a parameter when the read or write is called.
// This is example of private variable using this method.
function read_strvar(value) {
if (getcallingobject() == this) {
return value;
}
else {
return null;
}
}
// the new value of the 'variable' would be returned and GScript would catch the return value and assign it to the variable internally.
// indexes parameter would be an array of indexes used with the variable.
// ex: this.var1[3][5] = 4; would call: write_var1(<currentvalue>, 0, 4, {3, 5});
function write_strvar(value, operation, newvalue, indexes) {
// getcallingobject() is class function of util_callstack
if (getcallingobject() == this) {
switch (operation) {
case 0: // =
value[indexes[0], indexes[1]] = newvalue;
return value; // Gscript catches the return and sets that return to the variable's value.
case 1: // +=
value[indexes[0], indexes[1]] @= newvalue; // string append instead of addition.
return value;
default:
return value; // no other operations allowed for the variable.
}
}
else {
return value; // value is not modified, it is a private variable
}
}
Ideally if something like this were implemented it would only produce a slowdown with variables that are specifying a read and write function, or just one of the two.
And a more secure method would probably be a new type of script function definition:
PHP Code:
function onCreated() {
this.join("util_callstack");
this.strvar = "3"; // is using the special defined functions.
}
varread strvar(value) {
return value;
}
varwrite strvar(value, operation, newvalue, indexes) {
// do stuff
}
Its a stretch but its something I think might be interesting if used properly.