I had the following code, which is supposed to randomly select a system and calculate the route to that system from the player's current system:
Code: Select all
var amnestySystem = Math.floor(Math.random() * 256);
var amnestyRoute = system.info.routeToSystem(System.infoForSystem(galaxyNumber, amnestySystem), "OPTIMIZED_BY_TIME");
amnestyRoute
was always null
.I replaced it with a this.variable:
Code: Select all
this.amnestySystem = Math.floor(Math.random() * 256);
this.amnestyRoute = system.info.routeToSystem(System.infoForSystem(galaxyNumber, this.amnestySystem), "OPTIMIZED_BY_TIME");
this.amnestyRoute
was always null
.Then I thought: perhaps inside the SystemInfo object (not sure whether the outer or the inner, or both)
this
doesn't refer to my script anymore, so I tried:
Code: Select all
this.amnestySystem = Math.floor(Math.random() * 256);
this.amnestyRoute = system.info.routeToSystem(System.infoForSystem(galaxyNumber, worldScripts.Anarchies.amnestySystem), "OPTIMIZED_BY_TIME");
I haven't quite understood yet, however, why this is so. Can I get some more enlightenment about
this
? Where is it supposed to refer to what?