Fractal Softworks Forum

Please login or register.

Login with username, password and session length
Pages: [1] 2

Author Topic: How to add a ship into a fleet?  (Read 4885 times)

xangle13

  • Lieutenant
  • **
  • Posts: 68
    • View Profile
How to add a ship into a fleet?
« on: January 22, 2013, 08:55:48 PM »

I encounter a problem.
An error when I create a ship.

Code:

FleetMemberAPI fleetMember = (Global.getFactory()).createFleetMember(FleetMemberType.SHIP, treasureMapJigsawK.jigsawName);

treasureMapJigsawK is my custom object.
property jigsawName as String "C3_A1_Normal" a ship variant.



Log:

78976 [Thread-6] ERROR com.fs.starfarer.combat.D  - java.lang.NullPointerException
java.lang.NullPointerException
   at data.scripts.world.corvus.logic.TreasureMap.jigsawTreasureMap(TreasureMap.java:140)
   at data.scripts.world.corvus.logic.TreasureMaps.jigsawTreasureMaps(TreasureMaps.java:69)
   at data.scripts.world.corvus.TreasureMapSysyem.spawnFleet(TreasureMapSysyem.java:30)
   at data.scripts.world.BaseSpawnPoint.advance(BaseSpawnPoint.java:52)
   at com.fs.starfarer.campaign.BaseLocation.advance(Unknown Source)
   at com.fs.starfarer.campaign.CampaignEngine.advance(Unknown Source)
   at com.fs.starfarer.campaign.A.super(Unknown Source)
   at com.fs.starfarer.A.???000(Unknown Source)
   at com.fs.A.A.new(Unknown Source)
   at com.fs.starfarer.combat.D.o00000(Unknown Source)
   at com.fs.starfarer.StarfarerLauncher$2.run(Unknown Source)
   at java.lang.Thread.run(Thread.java:619)
Logged

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 24149
    • View Profile
Re: How to add a ship into a fleet?
« Reply #1 on: January 23, 2013, 10:47:20 AM »

Can you post the code for the function that's making this call?

data.scripts.world.corvus.logic.TreasureMap.jigsawTreasureMap(TreasureMap.java:140)

If this is the line that's giving you an error:
FleetMemberAPI fleetMember = (Global.getFactory()).createFleetMember(FleetMemberType.SHIP, treasureMapJigsawK.jigsawName);


Then I'm fairly certain that treasureMapJigsawK is null. If the error happened inside createFleetMember, the stack trace would have createFleetMember in it.
Logged

xangle13

  • Lieutenant
  • **
  • Posts: 68
    • View Profile
Re: How to add a ship into a fleet?
« Reply #2 on: January 23, 2013, 07:46:50 PM »

Can you post the code for the function that's making this call?

data.scripts.world.corvus.logic.TreasureMap.jigsawTreasureMap(TreasureMap.java:140)

If this is the line that's giving you an error:
FleetMemberAPI fleetMember = (Global.getFactory()).createFleetMember(FleetMemberType.SHIP, treasureMapJigsawK.jigsawName);


Then I'm fairly certain that treasureMapJigsawK is null. If the error happened inside createFleetMember, the stack trace would have createFleetMember in it.

It's very strange if that is null.

This is how I new this object:

treasureMap.addTestimonial(new TreasureMapJigsaw("C3_A1_Normal","SHIP",1));

And this is how I create the ship:

                     }else if((treasureMapJigsawK.jigsawType).equals("SHIP")){
                        for(int n = 0;n < treasureMapJigsawK.jigsawAmount;n++){
                           FleetMemberAPI fleetMember = (Global.getFactory()).createFleetMember(FleetMemberType.SHIP, treasureMapJigsawK.jigsawName);
                           cargo.getMothballedShips().addFleetMember(fleetMember);
                        }
                     }
Logged

xangle13

  • Lieutenant
  • **
  • Posts: 68
    • View Profile
Re: How to add a ship into a fleet?
« Reply #3 on: January 23, 2013, 07:49:54 PM »

Can you post the code for the function that's making this call?

data.scripts.world.corvus.logic.TreasureMap.jigsawTreasureMap(TreasureMap.java:140)

If this is the line that's giving you an error:
FleetMemberAPI fleetMember = (Global.getFactory()).createFleetMember(FleetMemberType.SHIP, treasureMapJigsawK.jigsawName);


Then I'm fairly certain that treasureMapJigsawK is null. If the error happened inside createFleetMember, the stack trace would have createFleetMember in it.


package data.scripts.world.corvus.logic;

@SuppressWarnings("unchecked")
public class TreasureMapJigsaw{
   
   public String jigsawName;
   public String jigsawType;
   public int jigsawPosition;
   public float jigsawAmount;
   
   public TreasureMapJigsaw(String jigsawName,int jigsawPosition,float jigsawAmount){
      this.jigsawName = jigsawName;
      this.jigsawType = null;
      this.jigsawPosition = jigsawPosition;
      this.jigsawAmount = jigsawAmount;
   }
   
   public TreasureMapJigsaw(String jigsawName,String jigsawType,float jigsawAmount){
      this.jigsawName = jigsawName;
      this.jigsawType = jigsawType;
      this.jigsawPosition = 0;
      this.jigsawAmount = jigsawAmount;
   }
   
   public TreasureMapJigsaw(String jigsawName,String jigsawType,int jigsawPosition,float jigsawAmount){
      this.jigsawName = jigsawName;
      this.jigsawType = jigsawType;
      this.jigsawPosition = jigsawPosition;
      this.jigsawAmount = jigsawAmount;
   }
}

Logged

xangle13

  • Lieutenant
  • **
  • Posts: 68
    • View Profile
Re: How to add a ship into a fleet?
« Reply #4 on: January 23, 2013, 08:05:29 PM »

Can you post the code for the function that's making this call?

data.scripts.world.corvus.logic.TreasureMap.jigsawTreasureMap(TreasureMap.java:140)

If this is the line that's giving you an error:
FleetMemberAPI fleetMember = (Global.getFactory()).createFleetMember(FleetMemberType.SHIP, treasureMapJigsawK.jigsawName);


Then I'm fairly certain that treasureMapJigsawK is null. If the error happened inside createFleetMember, the stack trace would have createFleetMember in it.


package data.scripts.world.corvus.logic;

import java.awt.Color;
import java.util.List;
import java.util.ArrayList;

import com.fs.starfarer.api.Global;
import com.fs.starfarer.api.campaign.CampaignFleetAPI;
import com.fs.starfarer.api.campaign.SectorAPI;
import com.fs.starfarer.api.campaign.CargoAPI;
import com.fs.starfarer.api.campaign.CargoAPI.CrewXPLevel;
import com.fs.starfarer.api.campaign.CargoStackAPI;
import com.fs.starfarer.api.campaign.FleetDataAPI;
import com.fs.starfarer.api.fleet.FleetMemberAPI;
import com.fs.starfarer.api.fleet.FleetMemberType;
import com.fs.starfarer.api.FactoryAPI;

import data.scripts.world.corvus.logic.TreasureMapJigsaw;

@SuppressWarnings("unchecked")
public class TreasureMap{
   
   public String treasureMapName;
   public double decipheringChance;
   public List jigsawList;
   public List testimonialList;
   public boolean achieve;
   public int scheduleMin;
   public int scheduleMax;
   public int scheduleAdd;
   
   public TreasureMap(String treasureMapName, double decipheringChance, int scheduleMin, int scheduleMax, int scheduleAdd){
      this.treasureMapName = treasureMapName;
      this.decipheringChance = decipheringChance;
      this.jigsawList = new ArrayList();
      this.testimonialList = new ArrayList();
      this.achieve = false;
      this.scheduleMin = scheduleMin;
      this.scheduleMax = scheduleMax;
      this.scheduleAdd = scheduleAdd;
   }
   
   public void addJigsaw(TreasureMapJigsaw treasureMapJigsaw){
      this.jigsawList.add(treasureMapJigsaw);
   }
   
   public void addTestimonial(TreasureMapJigsaw treasureMapTestimonial){
      this.testimonialList.add(treasureMapTestimonial);
   }
   
   public int jigsawTreasureMap(CargoAPI cargo){
      List playerCargoList = cargo.getStacksCopy();
      int scheduleReturn = 0;
      
      if(playerCargoList.size() > 0){
         for(int i = 0;i < playerCargoList.size();i++){
            CargoStackAPI playerCargo = (CargoStackAPI)playerCargoList.get(i);
            
            TreasureMapJigsaw treasureMapJigsaw = (TreasureMapJigsaw)this.jigsawList.get(0);
            if((treasureMapJigsaw.jigsawName).equals(playerCargo.getData())){
               
               boolean complete = true;
               for(int k = 0;(k < this.jigsawList.size())&&complete;k++){
                  TreasureMapJigsaw treasureMapJigsawK = (TreasureMapJigsaw)this.jigsawList.get(k);
                  if((int)(treasureMapJigsawK.jigsawPosition / 7) != (int)(((i % 7) + treasureMapJigsawK.jigsawPosition - treasureMapJigsaw.jigsawPosition) / 7)){
                     complete = false;
                  }
               }
               
               if(complete){
                  for(int k = 1;(k < this.jigsawList.size())&&complete;k++){
                     TreasureMapJigsaw treasureMapJigsawK = (TreasureMapJigsaw)this.jigsawList.get(k);
                     if((i + treasureMapJigsawK.jigsawPosition - treasureMapJigsaw.jigsawPosition) < playerCargoList.size()){
                        CargoStackAPI playerCargoNext = (CargoStackAPI)playerCargoList.get(i + treasureMapJigsawK.jigsawPosition - treasureMapJigsaw.jigsawPosition);
                        if(!(treasureMapJigsawK.jigsawName).equals(playerCargoNext.getData())){
                           complete = false;
                        }else if(playerCargoNext.getSize() < treasureMapJigsawK.jigsawAmount){
                           complete = false;
                        }
                     }else{
                        complete = false;
                     }
                  }
               }
               
               boolean decipheringComplete = true;
               if(complete){
                  if((double)Math.random() >= this.decipheringChance){
                     complete = false;
                     decipheringComplete = false;
                  }
               }
               
               if(!complete){
                  if(!decipheringComplete){
                     Global.getSectorAPI().addMessage("????? " + this.treasureMapName + " ??????????", new Color((int)155,(int)0,(int)0,(int)255));
                  }
               }else{
                  if(!this.achieve){
                     scheduleReturn = this.scheduleAdd;
                     this.achieve = true;
                  }
                  
                  Global.getSectorAPI().addMessage("?????? " + this.treasureMapName + " ????", new Color((int)0,(int)255,(int)0,(int)255));
                  
                  for(int k = 0;k < this.jigsawList.size();k++){
                     TreasureMapJigsaw treasureMapJigsawK = (TreasureMapJigsaw)this.jigsawList.get(k);
                     if(!("LINKER").equals(treasureMapJigsawK.jigsawType)){
                        cargo.removeItems(CargoAPI.CargoItemType.RESOURCES, treasureMapJigsawK.jigsawName, treasureMapJigsawK.jigsawAmount);
                        //CargoStackAPI playerCargoNext = (CargoStackAPI)playerCargoList.get(i + treasureMapJigsawK.jigsawPosition);
                        //playerCargoNext.subtract(treasureMapJigsawK.jigsawAmount);
                     }
                  }
                  
                  for(int k = 0;k < this.testimonialList.size();k++){
                     TreasureMapJigsaw treasureMapJigsawK = (TreasureMapJigsaw)this.testimonialList.get(k);
                     
                     if((treasureMapJigsawK.jigsawType).equals("ITEM")){
                        cargo.addItems(CargoAPI.CargoItemType.RESOURCES, treasureMapJigsawK.jigsawName, treasureMapJigsawK.jigsawAmount);
                     }else if((treasureMapJigsawK.jigsawType).equals("WEAPON")){
                        cargo.addWeapons(treasureMapJigsawK.jigsawName, (int)treasureMapJigsawK.jigsawAmount);
                     }else if((treasureMapJigsawK.jigsawType).equals("FUEL")){
                        cargo.addFuel(treasureMapJigsawK.jigsawAmount);
                     }else if((treasureMapJigsawK.jigsawType).equals("SUPPLY")){
                        cargo.addSupplies(treasureMapJigsawK.jigsawAmount);
                     }else if((treasureMapJigsawK.jigsawType).equals("CREW")){
                        if((treasureMapJigsawK.jigsawName).equals("REGULAR")){
                           cargo.addCrew(CargoAPI.CrewXPLevel.REGULAR, (int)treasureMapJigsawK.jigsawAmount);
                        }else if((treasureMapJigsawK.jigsawName).equals("VETERAN")){
                           cargo.addCrew(CargoAPI.CrewXPLevel.VETERAN, (int)treasureMapJigsawK.jigsawAmount);
                        }else if((treasureMapJigsawK.jigsawName).equals("ELITE")){
                           cargo.addCrew(CargoAPI.CrewXPLevel.ELITE, (int)treasureMapJigsawK.jigsawAmount);
                        }else{
                           cargo.addCrew(CargoAPI.CrewXPLevel.GREEN, (int)treasureMapJigsawK.jigsawAmount);
                        }
                     }else if((treasureMapJigsawK.jigsawType).equals("SHIP")){
                        for(int n = 0;n < treasureMapJigsawK.jigsawAmount;n++){
                           //cargo.addMothballedShip(FleetMemberType.SHIP , treasureMapJigsawK.jigsawName, null);
                           if(treasureMapJigsawK.jigsawName != null){
                              FleetMemberAPI fleetMember = (Global.getFactory()).createFleetMember(FleetMemberType.SHIP, treasureMapJigsawK.jigsawName);
                              cargo.getMothballedShips().addFleetMember(fleetMember);
                           }
                        }
                     }else if((treasureMapJigsawK.jigsawType).equals("WING")){
                        for(int n = 0;n < treasureMapJigsawK.jigsawAmount;n++){
                           //cargo.addMothballedShip(FleetMemberType.FIGHTER_WING , treasureMapJigsawK.jigsawName, null);
                           if(treasureMapJigsawK.jigsawName != null){
                              FleetMemberAPI fleetMember = (Global.getFactory()).createFleetMember(FleetMemberType.FIGHTER_WING, treasureMapJigsawK.jigsawName);
                              cargo.getMothballedShips().addFleetMember(fleetMember);
                           }
                        }
                     }
                  }
               }
            }
         }
      }
      return scheduleReturn;
   }
}
Logged

xangle13

  • Lieutenant
  • **
  • Posts: 68
    • View Profile
Re: How to add a ship into a fleet?
« Reply #5 on: January 23, 2013, 08:08:43 PM »

Can you post the code for the function that's making this call?

data.scripts.world.corvus.logic.TreasureMap.jigsawTreasureMap(TreasureMap.java:140)

If this is the line that's giving you an error:
FleetMemberAPI fleetMember = (Global.getFactory()).createFleetMember(FleetMemberType.SHIP, treasureMapJigsawK.jigsawName);


Then I'm fairly certain that treasureMapJigsawK is null. If the error happened inside createFleetMember, the stack trace would have createFleetMember in it.


package data.scripts.world.corvus.logic;

import java.util.List;
import java.util.ArrayList;

import com.fs.starfarer.api.Global;
import com.fs.starfarer.api.campaign.CampaignFleetAPI;
import com.fs.starfarer.api.campaign.SectorAPI;
import com.fs.starfarer.api.campaign.CargoAPI;
import com.fs.starfarer.api.campaign.CargoAPI.CrewXPLevel;
import com.fs.starfarer.api.campaign.CargoStackAPI;

import data.scripts.world.corvus.logic.TreasureMapJigsaw;
import data.scripts.world.corvus.logic.TreasureMap;

@SuppressWarnings("unchecked")
public class TreasureMaps {
   
   private final SectorAPI sector;
   private List maps;

   public TreasureMaps(SectorAPI sector) {
      this.sector = sector;
      this.maps = new ArrayList();
     
      TreasureMap treasureMap;
     
      //formula 1
      treasureMap = new TreasureMap("formula 1",0.1d);
     
      treasureMap.addJigsaw(new TreasureMapJigsaw("tm_1_0",0,1));
      treasureMap.addJigsaw(new TreasureMapJigsaw("tm_1_1",1,1));
      treasureMap.addJigsaw(new TreasureMapJigsaw("tm_1_2",7,1));
      treasureMap.addJigsaw(new TreasureMapJigsaw("tm_1_3",8,1));
     
      treasureMap.addTestimonial(new TreasureMapJigsaw("tm_1","ITEM",1));
     
      this.maps.add(treasureMap);
     
      //formula 2
      treasureMap = new TreasureMap("formula 2",0.3d);
     
      treasureMap.addJigsaw(new TreasureMapJigsaw("bp_1_0",1,1));
      treasureMap.addJigsaw(new TreasureMapJigsaw("bp_1_1",2,1));
      treasureMap.addJigsaw(new TreasureMapJigsaw("bp_1_2",7,1));
      treasureMap.addJigsaw(new TreasureMapJigsaw("bp_1_3",8,1));
      treasureMap.addJigsaw(new TreasureMapJigsaw("bp_1_4",9,1));
      treasureMap.addJigsaw(new TreasureMapJigsaw("bp_1_5",14,1));
      treasureMap.addJigsaw(new TreasureMapJigsaw("bp_1_6",15,1));
     
      treasureMap.addTestimonial(new TreasureMapJigsaw("bp_1","ITEM",1));
      treasureMap.addTestimonial(new TreasureMapJigsaw("C3_A1_Normal","SHIP",1));
     
      this.maps.add(treasureMap);
     
   }

   public void jigsawTreasureMaps() {
      CampaignFleetAPI fleet = sector.getPlayerFleet();
      CargoAPI cargo = fleet.getCargo();
     
      for(int i = 0;i < this.maps.size();i++){
         TreasureMap treasureMap = (TreasureMap)this.maps.get(i);
         treasureMap.jigsawTreasureMap(cargo);
      }
   }
}
Logged

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 24149
    • View Profile
Re: How to add a ship into a fleet?
« Reply #6 on: January 24, 2013, 11:34:36 AM »

By the way - you can use [code] tags to display code, like this:

Code
for(int n = 0;n < treasureMapJigsawK.jigsawAmount;n++){
//cargo.addMothballedShip(FleetMemberType.SHIP , treasureMapJigsawK.jigsawName, null);
  if(treasureMapJigsawK.jigsawName != null){
    FleetMemberAPI fleetMember = (Global.getFactory()).createFleetMember(FleetMemberType.SHIP, treasureMapJigsawK.jigsawName);
    cargo.getMothballedShips().addFleetMember(fleetMember);
  }
}

That makes it much easier to read.

Now - this line:
FleetMemberAPI fleetMember = (Global.getFactory()).createFleetMember(FleetMemberType.SHIP, treasureMapJigsawK.jigsawName);

Are you absolutely sure that this is the same code that's throwing the exception? I don't see how it could possibly throw a NullPointerException from here. treasureMapJigsawK is not null or it would have died on the previous line. Global.getFactory() is also extremely unlikely to be null (it'd have to be a pretty major bug in the game and would have come up elsewhere by now...).
Logged

xangle13

  • Lieutenant
  • **
  • Posts: 68
    • View Profile
Re: How to add a ship into a fleet?
« Reply #7 on: January 24, 2013, 07:15:28 PM »

Im quite sure.
I read yesterday and add the check:
if(treasureMapJigsawK.jigsawName != null)
And the same error.
I also try more direct way:
FleetMemberAPI fleetMember = (Global.getFactory()).createFleetMember(FleetMemberType.SHIP, "C3_A1_Normal");
And later I chose a variant from basal game.
All fail.
I found that,if I set treasureMapJigsawK.jigsawName a wrong hull name that do not exist.
The error will tell me the hull do not exist.
Maybe this error comes from the process when create ship.
When initlize ship attribute?

By the way - you can use [code] tags to display code, like this:

Code
for(int n = 0;n < treasureMapJigsawK.jigsawAmount;n++){
//cargo.addMothballedShip(FleetMemberType.SHIP , treasureMapJigsawK.jigsawName, null);
  if(treasureMapJigsawK.jigsawName != null){
    FleetMemberAPI fleetMember = (Global.getFactory()).createFleetMember(FleetMemberType.SHIP, treasureMapJigsawK.jigsawName);
    cargo.getMothballedShips().addFleetMember(fleetMember);
  }
}

That makes it much easier to read.

Now - this line:
FleetMemberAPI fleetMember = (Global.getFactory()).createFleetMember(FleetMemberType.SHIP, treasureMapJigsawK.jigsawName);

Are you absolutely sure that this is the same code that's throwing the exception? I don't see how it could possibly throw a NullPointerException from here. treasureMapJigsawK is not null or it would have died on the previous line. Global.getFactory() is also extremely unlikely to be null (it'd have to be a pretty major bug in the game and would have come up elsewhere by now...).
« Last Edit: January 24, 2013, 07:24:57 PM by xangle13 »
Logged

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 24149
    • View Profile
Re: How to add a ship into a fleet?
« Reply #8 on: January 24, 2013, 08:12:30 PM »

78976 [Thread-6] ERROR com.fs.starfarer.combat.D  - java.lang.NullPointerException
java.lang.NullPointerException
   at data.scripts.world.corvus.logic.TreasureMap.jigsawTreasureMap(TreasureMap.java:140)
   at data.scripts.world.corvus.logic.TreasureMaps.jigsawTreasureMaps(TreasureMaps.java:69)
   at data.scripts.world.corvus.TreasureMapSysyem.spawnFleet(TreasureMapSysyem.java:30)
   at data.scripts.world.BaseSpawnPoint.advance(BaseSpawnPoint.java:52)
   at com.fs.starfarer.campaign.BaseLocation.advance(Unknown Source)
   at com.fs.starfarer.campaign.CampaignEngine.advance(Unknown Source)
   at com.fs.starfarer.campaign.A.super(Unknown Source)
   at com.fs.starfarer.A.???000(Unknown Source)
   at com.fs.A.A.new(Unknown Source)
   at com.fs.starfarer.combat.D.o00000(Unknown Source)
   at com.fs.starfarer.StarfarerLauncher$2.run(Unknown Source)
   at java.lang.Thread.run(Thread.java:619)

Thing is, this error is happening on line 140 in TreasureMap. It's NOT happening within that function call - it's happening in that line. There are only 2 candidates for null pointer access there, which I talked about in the previous call.

When you say "same" error, do you just mean NullPointerException, or the exact same stack trace, down to the line numbers? There can be many different causes of an NPE. Something about this doesn't make sense.
Logged

xangle13

  • Lieutenant
  • **
  • Posts: 68
    • View Profile
Re: How to add a ship into a fleet?
« Reply #9 on: January 24, 2013, 09:06:20 PM »

My code changes a little these days.
So I will test that again and tell you the consequence.

78976 [Thread-6] ERROR com.fs.starfarer.combat.D  - java.lang.NullPointerException
java.lang.NullPointerException
   at data.scripts.world.corvus.logic.TreasureMap.jigsawTreasureMap(TreasureMap.java:140)
   at data.scripts.world.corvus.logic.TreasureMaps.jigsawTreasureMaps(TreasureMaps.java:69)
   at data.scripts.world.corvus.TreasureMapSysyem.spawnFleet(TreasureMapSysyem.java:30)
   at data.scripts.world.BaseSpawnPoint.advance(BaseSpawnPoint.java:52)
   at com.fs.starfarer.campaign.BaseLocation.advance(Unknown Source)
   at com.fs.starfarer.campaign.CampaignEngine.advance(Unknown Source)
   at com.fs.starfarer.campaign.A.super(Unknown Source)
   at com.fs.starfarer.A.???000(Unknown Source)
   at com.fs.A.A.new(Unknown Source)
   at com.fs.starfarer.combat.D.o00000(Unknown Source)
   at com.fs.starfarer.StarfarerLauncher$2.run(Unknown Source)
   at java.lang.Thread.run(Thread.java:619)

Thing is, this error is happening on line 140 in TreasureMap. It's NOT happening within that function call - it's happening in that line. There are only 2 candidates for null pointer access there, which I talked about in the previous call.

When you say "same" error, do you just mean NullPointerException, or the exact same stack trace, down to the line numbers? There can be many different causes of an NPE. Something about this doesn't make sense.
Logged

xangle13

  • Lieutenant
  • **
  • Posts: 68
    • View Profile
Re: How to add a ship into a fleet?
« Reply #10 on: January 24, 2013, 09:19:52 PM »

Well I try a lot.And at last:
code start at line 137
                        for(int n = 0;n < treasureMapJigsawK.jigsawAmount;n++){
                           //cargo.addMothballedShip(FleetMemberType.SHIP , treasureMapJigsawK.jigsawName, null);
                           if(treasureMapJigsawK.jigsawName != null){
                              FleetMemberAPI fleetMember = (Global.getFactory()).createFleetMember(FleetMemberType.SHIP, treasureMapJigsawK.jigsawName);
                              if(fleetMember != null){
                                 cargo.getMothballedShips().addFleetMember(fleetMember);
                              }
                           }
                        }


And log:

73543 [Thread-6] ERROR com.fs.starfarer.combat.D  - java.lang.NullPointerException
java.lang.NullPointerException
   at data.scripts.world.corvus.logic.TreasureMap.jigsawTreasureMap(TreasureMap.java:142)
   at data.scripts.world.corvus.logic.TreasureMaps.jigsawTreasureMaps(TreasureMaps.java:69)
   at data.scripts.world.corvus.TreasureMapSysyem.spawnFleet(TreasureMapSysyem.java:30)
   at data.scripts.world.BaseSpawnPoint.advance(BaseSpawnPoint.java:52)
   at com.fs.starfarer.campaign.BaseLocation.advance(Unknown Source)
   at com.fs.starfarer.campaign.CampaignEngine.advance(Unknown Source)
   at com.fs.starfarer.campaign.A.super(Unknown Source)
   at com.fs.starfarer.A.???000(Unknown Source)
   at com.fs.A.A.new(Unknown Source)
   at com.fs.starfarer.combat.D.o00000(Unknown Source)
   at com.fs.starfarer.StarfarerLauncher$2.run(Unknown Source)
   at java.lang.Thread.run(Thread.java:619)

It seems happen on addFleetMember()
Logged

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 24149
    • View Profile
Re: How to add a ship into a fleet?
« Reply #11 on: January 25, 2013, 11:45:24 AM »

addFleetMember is not in the stack trace, so I don't think that's where it's happening.

Line 142 seems to be:
cargo.getMothballedShips().addFleetMember(fleetMember);

Right? So, the only options are that 1) cargo is null or 2) the return value of getMothballedShips() is null. Either could be the case (are you calling initMothballedShips(String factionId) on the cargo at any point? If not, you need to.)
Logged

xangle13

  • Lieutenant
  • **
  • Posts: 68
    • View Profile
Re: How to add a ship into a fleet?
« Reply #12 on: January 25, 2013, 11:15:45 PM »

addFleetMember is not in the stack trace, so I don't think that's where it's happening.

Line 142 seems to be:
cargo.getMothballedShips().addFleetMember(fleetMember);

Right? So, the only options are that 1) cargo is null or 2) the return value of getMothballedShips() is null. Either could be the case (are you calling initMothballedShips(String factionId) on the cargo at any point? If not, you need to.)


It's better now.I used initMothballedShips("player") and do not get a error.
But the ship still didn't added to my fleet.
Logged

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 24149
    • View Profile
Re: How to add a ship into a fleet?
« Reply #13 on: January 26, 2013, 07:16:44 PM »

Well, that doesn't add it to the fleet, but to the fleet's "cargo". You can also call addFleetMember on the fleet itself.
Logged

xangle13

  • Lieutenant
  • **
  • Posts: 68
    • View Profile
Re: How to add a ship into a fleet?
« Reply #14 on: January 26, 2013, 09:21:17 PM »

Well, that doesn't add it to the fleet, but to the fleet's "cargo". You can also call addFleetMember on the fleet itself.

All ok now!
Thanks very much!
Now I can make some cool missions reward ships.
Logged
Pages: [1] 2