jh145 wrote:How do I define a worldScript which will be called for the player only?
Any ship script event handler can be used on a world script and applies to the player ship only in that case. This also keeps your player ship script events separated from everyone else's.
The only time I think you'd be better to define events on the player ship script were if they were specific to the ship hull type of the player, and in that case you'd be best predefining them by attaching the ship script in
shipdata.plist
Norby wrote:Even you can define the equipment activated and mode functions here also if you like to see your whole code in a single editor window.
You
can do that, but I wouldn't recommend it, because the two functions will get called in different contexts to the rest of the script, so code like this will mysteriously fail
Code: Select all
this.$equipmentStatus = false;
this.shipWillEnterWitchspace = function() {
this.$equipmentStatus = false;
}
this.$shipDockedWithStation = function() {
if (this.$equipmentStatus) {
// do something
}
}
this.activated = function() {
this.$equipmentStatus = true;
}
because this.$equipmentStatus in the equipment script and this.$equipmentStatus in the world script are separate variables existing in separate running copies of the script source.
Having the code in two windows is a good thing, as it reminds you that they're separate scripts.