Thanks Kaks, I already thought that is was something like this. Therefor I later on used the function "rotationTo()" to change a Vector to an quaternion. The errors were gone but the station was still not aligned.
Now I used your code and first thought it also didn't do anything. But dumping the orientation before and after to the log showed it did something.:
To double check I added two stations and only changed the orientation of one. And yes, both had different orientations. To let the docking slit point to the planet I probably need an extra transformation of the vector, but that is for next week.
Getting there! I just realized that all the numbers given to a quaternion must be between -1 & 1; probably the results you're getting are based on the decimal part of the original factoryVector.
One way to improve matters is to use the direction function to normalize the vector:
In the very impressive list with changes in 1.71 I miss a note that subentity handling changed. And in my opinion for the better.
Yesterday I noticed that flashers of subentities also flash. They never did.
And now I noticed after shooting down a subentity from a ship that the enclosed "death_actions" were executed. I my case this was exactly what I needed.
sterday I noticed that flashers of subentities also flash. They never did.
And now I noticed after shooting down a subentity from a ship that the enclosed "death_actions" were executed. I my case this was exactly what I needed.
I don’t think this was intentional, so I guess it’s a misbug. The relationship between subentities and their superentities was made more explicit, and in the process various cases where they weren’t made properly were fixed.
I now look forward to reports that switchLightsOn/switchLightsOff don’t work for subentity flashers. :-) (Fixed for 1.72.)
I now look forward to reports that switchLightsOn/switchLightsOff don’t work for subentity flashers. (Fixed for 1.72.)
I think this is what most people want. All flashers on/off simultaneously by the AI commands because it should like one single ship.
In my case the subentity is seen by the player as an inactive separate thing. There I like it more to be off. By using the right commands I can switch the flashers of the subentity on/off independent of the main ship by:
The fix for 1.72 is hierarchical. Switching flashers on/off for an entity also switches the flashers for subentities, but subentities can be explicitly switched on/off separately from the parent.
As I mentioned before, please do a bug report or scripting requests thread entry for any situation where you need to use call. It won’t be available in the stable release.
As I mentioned before, please do a bug report or scripting requests thread entry for any situation where you need to use call. It won’t be available in the stable release.
I know, but this was just a quick test to see if it would work on a subentity. Switching lights would probably be useful to use from within the JS. I am sure there are more AI commands that are useful to be used from within a ship-script. In my current work I use several occasions were I let the JS switch the AI to a special state to execute some AI commands. This way avoiding the call function. An own function would be easier.
Only on working with the scripts, one notices which AI commands are really useful as JS functions. It will take some practice work to see what functions will get used. (e.g. launching ships directly from within a station script instead of telling the AI to do that). I'll make a list.
Question: I see that the thargoid curses ("%R, %R, %R"), when being killed are now realized in a ship-script, no longer in death_actions (there was also something in the release notes about this, wasn't it?). Does that mean that death_actions are no longer working or supported? So do I have to have ship-script, if I want a ship to send a message or set a variable on being killed?
Question: I see that the thargoid curses ("%R, %R, %R"), when being killed are now realized in a ship-script, no longer in death_actions (there was also something in the release notes about this, wasn't it?). Does that mean that death_actions are no longer working or supported? So do I have to have ship-script, if I want a ship to send a message or set a variable on being killed?
All foo_actions on ships will be deprecated, but still functional, in the MNSR (just like script.plist). Since 1.70, the various foo_actions (launch_actions, death_actions, script_actions and setup_actions) are dispatched through oolite-default-ship-script.js but should function exactly as before. The various built-in ships using actions (constrictor, Thargoid, cloaking device target) have been ported to JavaScript in part to demonstrate the principle, and in part because it’s more efficient.
I want to rotate a station with its heading towards the planet. I have a vector to rotate about and an angle for how much to rotate. But whenever I use it with the rotate command I get errors. I don't see what I do wrong.
Maybe I use the wrong syntax. For testing purposes I created next two commands. Both generate an error but I see not why:
new Quaternion().rotate(new Vector([1,0,0]), 0))
Exception: SyntaxError: missing ; before statement
Active script: "oolite-debug-console" 1.71
oolite-debug-console.js, line 159:
let result = eval(command);
new Quaternion(rotate(new Vector([1,0,0]), 0)))
Exception: SyntaxError: missing ; before statement
Active script: "oolite-debug-console" 1.71
oolite-debug-console.js, line 159:
let result = eval(command);
Or more specific: I have a station "this.grsStation" that I want to align with vector "this.grs.Vector".
let angle = this.grsStation.heading.angleTo(this.grsVector)
let cross = new Vector(this.grsStation.heading.cross(this.grsVector))
let quaternion = new Quaternion(this.grsStation.orientation.rotate(cross, angle))
log("cross: "+cross+", angle: "+angle+", quaternion: "+ quaternion)
this.grsStation.setOrientation(this.grsStation.orientation.rotate(cross, angle))
Hmm. rotate() is completely broken, by the look of things. (It fails to advance over the argument list before getting the angle argument. I haven’t seen this in tests because my tests used a list of numbers instead of a vector object). Not only that, but it’s causing a crashing double exception on my system. :-/
This is parsed as new (Quaternion().rotate(...)) rather than (new Quaternion()).rotate. (Remember, JS doesn’t have classes; the new operator can take essentially any object as an argument.) I’m not sure how this leads to a missing-semicolon error.
Also, you don’t need the brackets; new Vector(1, 0, 0) works and is marginally more efficient.
let angle = this.grsStation.heading.angleTo(this.grsVector)
let cross = new Vector(this.grsStation.heading.cross(this.grsVector))
let quaternion = new Quaternion(this.grsStation.orientation.rotate(cross, angle))
The news in this are making redundant copies. The following should have the same effect:
let angle = this.grsStation.heading.angleTo(this.grsVector);
let cross = this.grsStation.heading.cross(this.grsVector);
let quaternion = this.grsStation.orientation.rotate(cross, angle);
Hmm. rotate() is completely broken, by the look of things. (It fails to advance over the argument list before getting the angle argument. I haven’t seen this in tests because my tests used a list of numbers instead of a vector object). Not only that, but it’s causing a crashing double exception on my system. :-/
DIgging into this exception has exposed a huge set of related bugs based on me not quite understanding error handling in Spidermonkey. I now know how to fix them, but it’ll take a while since there are a few hundred.
Of course, it’s good that I know this so it gets fixed. I just wish I didn’t. :-)
Hmm. rotate() is completely broken, by the look of things.
Thanks for looking in to it. I somehow suspected that it was the rotate itself that was confused and not me. But because of my limited JS skills I wasn't sure.
Understanding vectors itself shouldn't be a to big problem. I have a background of chemical engineering and during my education there was enough in it about vector calculations. (But never used that part in practice).
Rotate won't be fixed until 1.72 so I go for my last resort to align the station: use the same method as used for the mainStation: just give it a random orientation and than place it at such a position around the planet that it is aligned. The method just looks stupid because you never know were it will be placed.
EDIT: Just tried it and the station is heading to the planet with its docking bay: