Page 2 of 3

Re: Boulders from asteroids question(s)

Posted: Mon Mar 07, 2011 8:38 am
by Commander McLane
Smivs wrote:
Am I the only person who finds the js sections almost impossible to navigate? Is there an index page or something I've missed?
http://wiki.alioth.net/index.php/Catego ... _Reference

And for all plist stuff http://wiki.alioth.net/index.php/Catego ... _scripting (the JS_reference is the first subcategory of this page). The scripting index page itself is among the subcategories of http://wiki.alioth.net/index.php/Category:Oolite.

If you have a look at the first page, the only thing you need to know is which JS object you want to manipulate. In your case a ship, because it's a ship which spawns the boulder. Therefore the reference page you need is http://wiki.alioth.net/index.php/Oolite ... ence:_Ship, and indeed that's where you find the spawn() method. The hint is in the word you type at the beginning of your command (in this case it's this.ship.).

If you follow Thargoids advice, you may consult two pages. As indicated by the word system. at the beginning of the command, it manipulates the system object. The reference page for that is http://wiki.alioth.net/index.php/Oolite ... ce:_System. That's where you find everything about the addShips() method. Later you see the word ship. again, which indicates that position is again a property of the ship, so you would search for it on http://wiki.alioth.net/index.php/Oolite ... ence:_Ship again. Only that this time you wouldn't find it there. It happens that ship is one of the sub-classes of entity (other sub-classes are for instance sun or planet), and all entities have a position. Therefore you find the position property in http://wiki.alioth.net/index.php/Oolite ... ce:_Entity.

If you would want to manipulate the player ship, your starting point would be http://wiki.alioth.net/index.php/Oolite ... PlayerShip. However, this covers only all things which are unique to a player ship. For all other aspects a player ship is only a sub-class of ship, which is only a sub-class of entity. Therefore you would have to consult one of those pages if you want to manipulate for instance the player ship's speed (shared by all ships) or position (shared by all entities).

Re: Boulders from asteroids question(s)

Posted: Mon Mar 07, 2011 8:51 am
by Eric Walch
Thargoid wrote:
Try replacing

Code: Select all

this.ship.spawn("boulder");
with

Code: Select all

system.addShips("boulder", 10, this.ship.position, 500);
That will add 10 boulders within 500m of the ships current position (or in this case the position it held when it died).

For exact details of what's done there, see the wiki.[/color]
But the spawn thing is specially mend for adding stuff inside the collision radius what makes it ideal for adding remaining parts after an explosion :wink:
Smivs wrote:
I did try this the other way round, with the ship being a sub-ent of the asteroid, and found it couldn't spawn anything, so it seems that sub-ents can't spawn stuff.
They can, look in my Griff krait modification were all the subents use scripts.

NB the index I always use is: [wiki]Oolite_JavaScript_Reference[/wiki]

Re: Boulders from asteroids question(s)

Posted: Mon Mar 07, 2011 6:46 pm
by Smivs
Thanks again, one and all.
The boulders are fine now, but I still have one annoying problem. I'm working on a salvage scenario, with a GalDrivePod as the item to be salvaged. I'm spawning two on the destruction of the ship, and what I want is the first one to install a Galactic Hyperdrive when scooped, which it does. However if the second one is scooped, or the player already has a GH installed, I want these to end up in the hold as Machinery.
On scooping the second pod, the console message says 'GalDrivePod scooped' and no machinery is appearing in the hold.

Code: Select all

this.shipWasScooped = function (scooper)
{
	if (scooper.isPlayer)
	{
		if (player.ship.equipmentStatus("EQ_GAL_DRIVE") !== "EQUIPMENT_OK")
		{
			player.ship.awardEquipment("EQ_GAL_DRIVE");
		}
		else
		{
			player.ship.awardCargo("Machinery", 1);
		}
	}
};
What have I done wrong?

Re: Boulders from asteroids question(s)

Posted: Mon Mar 07, 2011 6:59 pm
by Okti
Hi Smivs,

Pylon based equipments do not have status. I think we went through that in an earlier topic.

So checking for the status will not work at all.

I will try to find another way to check it. But you can always try to remove the equipment and if succesed you may do what ever you like.

Code: Select all

while (player.ship.removeEquipment("EQ_GAL_DRIVE_MINE"));
If I can help more pls. let me know.

Re: Boulders from asteroids question(s)

Posted: Mon Mar 07, 2011 7:13 pm
by Commander McLane
Okti wrote:
Hi Smivs,

Pylon based equipments do not have status.
This is not entirely correct.

Pylon based equipments do have status. There is, however, a bug in Oolite 1.75 which causes the status to be always "EQUIPMENT_UNAVAILABLE" (therefore it is always !== "EQUIPMENT_OK", and only the first part of the code is executed). This bug has already been fixed in trunk.

Therefore the code will not work as expected in 1.75, but it will work in 1.75.1 (and has worked before 1.75).

Re: Boulders from asteroids question(s)

Posted: Mon Mar 07, 2011 7:14 pm
by Smivs
Hi Okti, McLane, thanks, but these are not pylon mounted. Think of them as free-floating cargo containers that can be scooped.

Re: Boulders from asteroids question(s)

Posted: Mon Mar 07, 2011 7:18 pm
by Okti
I can not see any methods with player.ship.awardCargo

You must use manifest :D

Also if some line of code do not work, it is a good idea to check the latest.log.

Re: Boulders from asteroids question(s)

Posted: Mon Mar 07, 2011 7:45 pm
by Commander McLane
Okti wrote:
I can not see any methods with player.ship.awardCargo

You must use manifest :D
Ah, indeed! I missed that. awardCargo() was removed in 1.75 (or even in 1.74, I am not sure) and replaced with the more flexible manifest (see http://wiki.alioth.net/index.php/Oolite ... :_Manifest).

So what you need is player.ship.manifest.machinery += 1;

And you could first check for cargoSpaceAvailable, just like in the example on the Wiki page.

(Still, my remark about pylon-mounted equipment was true. :) It just had nothing to do with the matter at hand. :oops: )

Re: Boulders from asteroids question(s)

Posted: Mon Mar 07, 2011 7:47 pm
by Okti
Thanks Commander Mclane

also pls look at my location in the profile :D

Re: Boulders from asteroids question(s)

Posted: Mon Mar 07, 2011 7:53 pm
by Smivs
That's odd. because I got it from this.

Code: Select all

this.name			= "oolite-cloaking-device-pod";
this.author			= "Jens Ayton";
this.copyright		= "© 2007-2011 the Oolite team.";
this.version		= "1.75";


this.shipWasScooped = function (scooper)
{
	if (scooper.isPlayer)
	{
		if (player.ship.equipmentStatus("EQ_CLOAKING_DEVICE") !== "EQUIPMENT_OK")
		{
			player.ship.awardEquipment("EQ_CLOAKING_DEVICE");
			// Should we make it possible to repair?
			// EquipmentInfo.infoForKey("EQ_CLOAKING_DEVICE").effectiveTechLevel = 14;
		}
		else
		{
			player.ship.awardCargo("Gold", 100);
		}
	}
	// Should probably award 100 gold to non-player ships too, but they don’t have awardCargo at the moment.
};
Look familiar?

Re: Boulders from asteroids question(s)

Posted: Mon Mar 07, 2011 8:04 pm
by Okti
This means that code needs to be upgraded as well, I think you must report it under Testing and Bugs Thread

Re: Boulders from asteroids question(s)

Posted: Mon Mar 07, 2011 8:09 pm
by Smivs
Done.

Re: Boulders from asteroids question(s)

Posted: Mon Mar 07, 2011 8:11 pm
by Okti
:shock:

Re: Boulders from asteroids question(s)

Posted: Mon Mar 07, 2011 10:41 pm
by JensAyton
Commander McLane wrote:
Perhaps it is. I'm not sure whether a subentity can spawn something. Perhaps it can't.
Calling spawn on a subentity spawns objects near the witchpoint, as the subentity’s position is in parent-relative coordinates. This is half-fixed in r4442 by treating it as if spawn() had been called on the mother. This is imperfect because it uses the mother’s origin and radius, but doing it right would be too complex for MNSR (apparently we don’t have an absolutePosition method for subentities yet!).

Re: Boulders from asteroids question(s)

Posted: Mon Mar 07, 2011 11:04 pm
by Smivs
That explains that weird thing I got with the boulders appearing thousands of metres away.