As a fun hack I've embedded the Mozilla SpiderMonkey scripting engine into Oolite. It seems to work, so now I need to know if anyone would use it.
Anyone who's written an OXP is probably already comfortable with the PLIST scripting, but it's always bugged the hell out of me. OOScript was an attempt to improve the life of scripters but failed because (a) the script parser was broken until recently and (b) it could only do what the PLIST scripts could do - it was just syntactic sugar.
My first goal with the JavaScript engine would be to replicate what is possible with the existing PLIST scripts. This means I'll have to implement all the scripting commands and properties in the JavaScript object model. This will be a very big job.
I don't want to waste my time if everyone is happy with the PLIST scripts. So, would you OXP authors rather write your scripts in JavaScript or are you happy to stay as you are?
Here are some advantages of using JavaScript (my opinion, of course):
* Can use "or" as well as "and" in conditions (PLIST scripts can only do "and") eg
Code: Select all
if (PlanetNumber == 23 || PlanetNumber == 45) {
...
}
Code: Select all
var StartPlanet = 7;
...
if (PlanetNumber == StartPlanet) {
...
}
Code: Select all
var result = a * (b + c) / e;
The second stage of development would extend the object model available to scripts if we can think of things that are useful.
The third stage would be to modify the game engine so that OXP scripts could create new stuff that act as native game objects, like new weapons or equipment. I'm not clear on how that could be done (it may be too big a job).
Here is the dinky OXP script I'm testing with at the moment. You don't have to define event handlers for all the states - if you don't define one for say STATUS_LAUNCHING then your script doesn't get run while the player is in that state.
Don't worry about the crazy syntax for defining the event handlers. That will always stay the same (unless I can find a way to simplify it). You don't need to understand what it does, just copy it. Any functions you write to call from the event handlers will look much more understandable.
There is a ready made object called "Universe" which will have most of the stuff you do in scripts, like AddShips, AddMoon, etc, and references to other objects like PlayerEntity. GalaxyNumber and PlanetNumber are pre-supplied global variables that are always available. Other common variables will be available the same way. Mission variables will be held in an array so will be accessed like MissionVars["myVar"] = 10;
Code: Select all
this.Name = "testoxp";
this.Description = "A test OXP written using JavaScript";
this.Version = "1.0";
this.STATUS_DOCKED = function () {
Universe.Log(Name + ".STATUS_DOCKED");
}
this.STATUS_LAUNCHING = function () {
var pe = Universe.PlayerEntity;
Universe.Log(Name + ".STATUS_LAUNCHING " + pe.CommanderName + " has launched in a " + pe.ShipDescription + " into galaxy " + GalaxyNumber + ", planet " + PlanetNumber);
}
this.STATUS_EXITING_WITCHSPACE = function () {
Universe.Log(Name + ".STATUS_EXITING_WITCHSPACE into galaxy " + GalaxyNumber + ", planet " + PlanetNumber);
}
this.STATUS_IN_FLIGHT = function () {
Universe.Log(Name + ".STATUS_IN_FLIGHT in galaxy " + GalaxyNumber + ", planet " + PlanetNumber);
}