Page 2 of 8

Posted: Thu Dec 30, 2010 4:30 pm
by Mauiby de Fug
The way it's set to work is this:

You buy the wormhole generator as a piece of pylon based equipment.
You select your hyperspace destination in the usual way on the galactic map.
You fire the generator in the same way as you would a missile/mine.
The generator then exits the system to another system in range that is on the route to the hyperspace destination you selected, leaving a wormhole in it's wake.
You then follow it through the wormhole.
Once in the next system, the drone exits the system to the next system on the route.
You follow.
Repeat.

Posted: Thu Dec 30, 2010 4:37 pm
by Phantom Hoover
So it just makes a wormhole to <arbitrary system>, ignoring the 7 LY jump limit?

Posted: Thu Dec 30, 2010 4:58 pm
by Mauiby de Fug
No, it makes a series of wormholes to an arbitrary system, each of which is within the 7 LY jump limit.

Posted: Thu Dec 30, 2010 5:38 pm
by Commander McLane
Just to re-iterate what I said before:

I like the idea because (and as long as) it doesn't remove the need to do individual, consecutive jumps, as opposed to one long jump. (For instance, in the Escape Velocity series, you could buy a piece of equipment which allowed you to make series of jumps and emerge in your final destination system at once, skipping the intermediate systems altogether. I wouldn't like something like that for Oolite.)

Having individual, consecutive jumps makes you emerge in each of the intermediate systems, which means that in each of the intermediate systems something can go wrong. Something distracts you for 15 seconds, and your next connection wormhole is gone, leaving you stranded where you are. (Technically, you're not stranded, because you still have your tanks full and can continue to jump by yourself. But the nice flow of jumps is broken, and the expensive device is gone.) Failsafe technology is boring. The possibility of failure brings excitement.

I agree with the suggestion to make it a mission equipment rather than something everybody can buy all the time. At least the player could be awarded it first through a mission, before it perhaps becomes a regularly buyable piece of equipment (like the Gal Drive Mod in Cataclysm which allows you to reach isolated systems; first you get it in order to fulfill a mission, afterwards it becomes buyable).

So it's thumbs up from me! :D

Posted: Thu Dec 30, 2010 5:39 pm
by Phantom Hoover
Erm. If it just skips through systems with <= 7 LY jumps, how would you get across, say, the Great Rift in G7?

Posted: Thu Dec 30, 2010 5:40 pm
by Commander McLane
Phantom Hoover wrote:
Erm. If it just skips through systems with <= 7 LY jumps, how would you get across, say, the Great Rift in G7?
You wouldn't. That's not the purpose of this gadget.

Posted: Thu Dec 30, 2010 6:33 pm
by Mauiby de Fug
I'm quite happy for it only to be awarded after the completion of a mission - for one thing, it would give it some backstory/context. Suppose I'd better get my thinking cap on and come up with one, unless somebody else wants to do it!?

The script itself is very simple - 'tis just attached to a piece of equipment (with a nullAI.plist, which seems to work. I haven't got my head around AIs yet...) with the requisite shipdata, equipment and description plist entries.

Here it is in its entirety at the moment:

Code: Select all

this.name           = "Mauiby's Wormhole Drone";
this.author         = "Mauiby de Fug";
this.description    = "Generate the wormhole chain";
this.version        = "1.0";

var jumpChain;
var chainPos;

this.shipSpawned = function() {
	player.consoleMessage("Wormhole chain sequence activated...", 5);
	jumpChain = System.infoForSystem(galaxyNumber, System.ID).routeToSystem(System.infoForSystem(galaxyNumber, PlayerShip.targetSystem));
	chainPos = 1;
	log("Target system is " + PlayerShip.targetSystem);
	log("Route: " +jumpChain.route);
	log("Distance: "+jumpChain.distance);
	log("Time: "+jumpChain.time);
	log("Chain length: "+jumpChain.route.length);
	this.ship.velocity = player.ship.velocity;
	this.ship.orientation = player.ship.orientation;
	this.ship.position = player.ship.position.add(player.ship.orientation.vectorForward().multiply(4000));
	this.createWormhole();
}

this.shipExitedWormhole = function() {
	log("Am in system: "+System.ID);
	log("Want to go to: "+PlayerShip.targetSystem);
	if (PlayerShip.targetSystem != System.ID) {
		log("Want to create wormhole");
		this.createWormhole();
	}
}

this.createWormhole = function() {
	log("Position in chain: "+chainPos); 
	this.ship.fuel = 7;
	log("Can I jump?");
	log(this.ship.exitSystem(jumpChain.route[chainPos]));
	chainPos++;
}
As you can see, a fair amount of it is just logging, which can be deleted. Although this line is both logged, and implemented, at the same time, which seems strange to me.

Code: Select all

	log(this.ship.exitSystem(jumpChain.route[chainPos]));
I move the "ship" in front of the player for the first wormhole, mainly because it was easier to test. As you can see, I haven't added any useful things to it yet.

Question: when a ship fails to create a wormhole, is there any way to find out why not? I haven't got it to work past 6 or 7 jumps yet, and while that is in no way a bad thing in itself, I don't actually know what the cause is...

Also, feel free to tell me if there's any bad scripting in there, or better ways to achieve the required result! I mainly worked this out to learn, after all...

Posted: Thu Dec 30, 2010 7:48 pm
by Thargoid
You may want to have some way of checking that the wormhole that the player enters is the one that the device created. At the moment it doesn't seem to discriminate. Indeed with that script active, it will trigger when they pass through any wormhole.

Posted: Thu Dec 30, 2010 10:02 pm
by JensAyton
Mauiby de Fug wrote:
Although this line is both logged, and implemented, at the same time, which seems strange to me.

Code: Select all

	log(this.ship.exitSystem(jumpChain.route[chainPos]));
log() is a normal function. In a function call expression, the expressions making up the arguments are evaluated and the result passed to the function. In this case, jumpChain.route[chainPos] is evaluated (retrieving a value from the array), and passed to this.ship.exitSystem(). This returns true, which is then passed to log().
Mauiby de Fug wrote:
Also, feel free to tell me if there's any bad scripting in there, or better ways to achieve the required result! I mainly worked this out to learn, after all...
The values jumpChain and chainPos are declared as vars in global scope, which makes the properties of the global object, which is shared between all scripts. (This is a known deficiency in the JavaScript language itself.) They should either be made properties of this (preferably with a $ or _ in front, as they’re internal), or enclosed in a closure, which looks like this:

Code: Select all

(function () {
var jumpChain;
var chainPos;

this shipSpawned = …
/* rest of code*/
}).call(this);
In this approach, only the code within the anonymous outer function can see the variables, but they continue to exist when the callbacks are called.

You mix PlayerShip with player.ship. The preferred usage is player.ship. Accessing properties of PlayerShip could stop working in future. (Pretend it isn’t there.) In the same way, System.ID should be system.ID.

(PlayerShip and System are the “prototypes” of player.ship and system. In general, the prototype defines methods and properties that are shared by all objects of a certain type. For instance, the Vector3D prototype has the add() method, and every vector inherits it – unless a particular vector is given an add() method of its own. However, you can’t usefully call Vector3D.add() since there’s no actual vector data attached to the prototype. Conceptually, the same is true of PlayerShip, but since there’s only one player ship some of the methods use it directly instead of extracting it from the JavaScript “this” parameter, so calling them on the prototype works. You’ll get bitten if you try to use an inherited method or property, like PlayerShip.position, which is undefined. The situation for System is a bit more complex, but the convention is that you use lowercase system to refer to the current system, and uppercase System for methods that refer to other systems – namely those listed under Static Methods in the wiki.)

Oh, and instead of System.infoForSystem(galaxyNumber, system.ID) you can use system.info (which is the info for the current system).

Posted: Thu Dec 30, 2010 10:20 pm
by Cody
I sit and read these ‘technical’ posts, and sometimes a glimmer of comprehension hovers in front of my eyes, the old programmer buried deep in my head stirs and mutters, and I think that I understand… then the mirage dissolves in a puff of anti-logic, and I’m lost again… hey-ho!

Posted: Thu Dec 30, 2010 10:38 pm
by DaddyHoggy
El Viejo wrote:
I sit and read these ‘technical’ posts, and sometimes a glimmer of comprehension hovers in front of my eyes, the old programmer buried deep in my head stirs and mutters, and I think that I understand… then the mirage dissolves in a puff of anti-logic, and I’m lost again… hey-ho!
I know how you feel! My "proper" programming days are long gone - a bit of bug fixing is all I manage now.

Posted: Thu Dec 30, 2010 10:45 pm
by drew
I was following all the way up to the first bracket.

Cheers,

Drew.

Posted: Thu Dec 30, 2010 11:20 pm
by Yodeebe
me neither.
i tried it in ROT13, and it made a bit more sense, but not a lot.

Just out of interest though, do those words (in the script) actually do stuff, or are they just names for groups of ... errrr... programming?
Or is it just like a whole language where the words also 'function'?

I don't get how [ship.fly.to.station] makes a ship fly to the station (yay, my 1st oxp? 8) ) . surely it's not exclusive to Oolite?


thorry for the thtupid quethtion

Posted: Fri Dec 31, 2010 12:44 am
by JensAyton
We really need a tutorial that introduces JavaScript concepts and Oolite scripting as one package. Most of the introductions to JavaScript are either terrible or web-specific (most often both). Unfortunately, I’ve got lots of other things to do in my Oolite time and I’m terrible at explaining things. :-)

Posted: Fri Dec 31, 2010 1:34 am
by Yodeebe
don't worry.

i still wouldn't understand anyway. :?