Page 1 of 1

adding a ship to a group

Posted: Sun Feb 20, 2011 8:10 pm
by Commander McLane
Stupid question (and I think I knew it once, but I can't figure it out now):

How do I add a newly created ship to an existing ship group? Specifically how does the newly added ship get to know that it's part of a group now?

I want to make the fireworkers part of the station group. They're spawned like this:

Code: Select all

this.shipWillLaunchFromStation = function(station)
{
    if(player.ship.equipmentStatus("EQ_FIREWORKS") === "EQUIPMENT_OK")
    {
        var orientation = station.orientation
        this.fireworker = system.addShips("fireworks_fireworker", 1, station.position.add(orientation.vectorForward().multiply(3600)).add(orientation.vectorRight().multiply(500)), 0);
        this.fireworker[0].orientation = orientation;
        station.group.addShip(this.fireworker[0]);
        ...
I thought the last line would do the trick. However, it does only half the trick. The station is aware of the fireworkers. But the fireworkers themselves claim to belong to no group whatsoever. How can this be? And how can I make them aware of their new community?

Re: adding a ship to a group

Posted: Sun Feb 20, 2011 8:47 pm
by JensAyton
this.fireworker[0].group = station.group. Being a member of the group doesn’t make it the ship’s “main” group, because a ship can belong to any number of groups (and you can create groups to track any set of ships you please).

Re: adding a ship to a group

Posted: Sun Feb 20, 2011 8:57 pm
by Commander McLane
Ah, yes! And I did know that once. :oops:

Thanks, Ahruman! :D