I get it that calling statically or calling the instance change the context of your code visiblity, but it's getting me really mad there !
So i'm asking for a clearer answer here's what i'm seeing on my AI (i took great care of call them static with var.classfunc instead of classfunc but it doesn't work when neast call are done)
let's say i init the var ATEST in main.nut so i could get/change ATEST value from another class by init the class with a "main" variable, this way i will always grab my previous instance to keep its context and so, keep seeing my ATEST var from the class.
Code: Select all
in dummy.nut
class cDummy { main = null; constructor(main) { this.main=main; }}
function cDummy::print
{ AILog(ATEST); }
in main.nut (i don't show the full code, just for you to get the picture)
ATEST = null; dummy = null;
ATEST = "value"; dummy=cDummy(this);
dummy.print();
openttd will trigger the "ATEST doesn't exist"
So to solve that, i set the
Code: Select all
function cDummy::print
{ AILog(main.ATEST); }
But here's what happen, in neastest context, i can't use that trick anymore and i'm stuck, because context keep changing and i can't fix my code to keep seeing ATEST
again, i create another class, cDummy2, exactly a dup of cDummy with the same function (but cDummy2::print of course)
add dummy2 var in main.nut...
So:
dummy2.print and dummy.print work because they use main.ATEST to access the var
Now what drives me mad is that if i call dummy2 from dummy, context is again change and this time ATEST is not visible: here's come again the "ATEST doesn't exist" error...
I know how to see ATEST again (in that context ATEST is in main.main.ATEST)
But if i change let's say: cDummy2 code to use main.main.ATEST instead of main.ATEST i will not be able to use dummy2.print from main.nut (or other instance) as from that context ATEST is main.ATEST...
It's a pain because i use a class that handle my banking routines, and that class could be use from any other class and from main, so context is nearly unpredictable (it's not, but i have better things to do than looking who call who).
I suppose there's a solution or something i didn't catch there, else all AI would use main.nut for everything to avoid the problem and make one big main.nut file to not take care of that problem.
Anyone can me give hint or directions ?