so you can actually have "true static" variablesMy Conclusion:GML:function demo(n) constructor{ static abc = [n]; static push1 = function(){ abc[@ 0]++; } static push2 = function(){ abc[0] += 2; } static show = function(){ show_debug_message(abc); } } function test(){ var a = new demo(2);//public.abc = [2], a.abc is the public one. var b = new demo(5);//public.abc = [2], b.abc is the public one and will not be initialed again a.push1();//public abc[0] = 2+1, a.abc is the public one. a.show();// show pulic abc = [3] a.push2();//private a.abc[0] = public abc[0] + 2; a has his private abc now, the abc below is not the pulic one and be initialed from the public. a.show();// show private a.abc = [5] a.push1();//private a.abc[0]++ a.show();// show private a.abc = [6] a.push2();//private a.abc[0]+=2 a.show();// show private a.abc = [8] b.push1();//public abc[0] = 3+1, , b.abc is the public one. b.show();// show pulic abc = [4] b.push2();//private b.abc[0] = public.abc[0] + 2; b has his private abc now, the abc below is not the pulic one and be initialed from the public. b.show();// show private b.abc = [6] b.push1();//private b.abc[0]++ b.show();// show private b.abc = [7] b.push2();//private b.abc[0]+=2 b.show();//show private b.abc = [9] }
If struct only has public static member, it will operate the public one.
Once struct has it's own member, it will operate his private one and be initialed from the public.
using:
GML:
function TimeCamera() constructor
{
static staticVars = { times: ds_stack_create(), counter: 0 };
static SnapShot = function()
{
ds_stack_push(staticVars.times, get_timer());
staticVars.counter += 1;
}
static Pop = function()
{
if (staticVars.counter == 0) return false;
staticVars.counter -= 1;
return ds_stack_pop(staticVars.times);
}
}
and now all TimeCamera intances share the same static variables
[NOTE] This is a useless example