So I have objects saved in multiple lists for organizational purposes, for "Crew" objects (it's a ship sailing game). The structure is:
ListA = List<Crew> Crew1, crew2, crew3
ListB = List<Crew> Crew4, crew5, crew6
ListC = List<Crew> Crew7, crew8, crew9
ListD = List<List<Crew>> ListA, ListB, ListC
This works perfectly fine before I save the game. Removing or adding a crew from ListA would change it in ListA and ListD, and removing from ListD[0] would also remove from ListA..
However, after loading these lists, it's like they become permanently unlinked. Changing ListA doesn't alter ListD and vice versa.
I tried saving only ListD in the ES3 type and reconstructing the other lists on play, but that makes no difference.
Any idea what could cause this, and how to workaround this issue?
Saved lists not functioning correctly
Saved lists not functioning correctly
Last edited by Levgre on Mon Aug 17, 2020 7:33 pm, edited 1 time in total.
Re: Saved lists not functioning correctly
Hi there,
Please could you show me the code you're using to save and load your lists? And just to check, are you sure you're not using the same key for each list?
All the best,
Joel
Please could you show me the code you're using to save and load your lists? And just to check, are you sure you're not using the same key for each list?
All the best,
Joel
Re: Saved lists not functioning correctly
I just left in the relevant variables since it is pretty cluttered, hopefully this highlights what I'm doing wrong/gives some direction.
Code: Select all
public class Player : MonoBehaviour
{
public void SaveGame()
{
ES3.Save<PlayerSave>("PlayerSaveScript", PlayerSaveScript);
}
public void LoadGame()
{
PlayerSaveScript = ES3.Load("PlayerSaveScript", PlayerSaveScript);
}
}
public class PlayerSave : MonoBehaviour
{
public List<Faction> FactionList;
}
public class Faction
{
public List<Fleet> FactionFleets;
public Faction()
{
FactionFleets = new List<Fleet>();
}
}
public class Fleet
{
public List<Ship> FleetShips;
public Fleet()
{
FleetShips = new List<Ship>();
}
}
public class Ship
{
public List<List<Crew>> CrewLists;
public List<Crew> AllCrew;
public List<Crew> SailingCrew;
public List<Crew> MeleeCrew;
public List<Crew> CannonCrew;
}
public Ship()
{
AllCrew = new List<Crew>();
SailingCrew = new List<Crew>();
MeleeCrew = new List<Crew>();
CannonCrew = new List<Crew>();
CrewLists = new List<List<Crew>> { SailingCrew, CannonCrew, MeleeCrew};
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Crew
{
public float MeleeOffense;
public float MeleeDefense;
public float ShortRangeOffense;
public float LongRangeOffense;
public float RangedDefense;
public float Happiness;
public float Health;
public float Wage;
public float Age;
public float ConsumptionAmount;
public float Melee;
public float Ranged;
public float Cannoneering;
public float Sailing;
public float CurrentMelee;
public float CurrentRanged;
public float CurrentCannoneering;
public float CurrentSailing;
public List<float> CharacterStats;
public float[] CurrentCharacterStats;
public float[] CharacterStatProgress;
public string FirstName;
public string LastName;
public bool IsOfficer;
public bool IsPlayer;
public bool IsCaptain;
public bool IsCrew;
public bool IsBoarding;
public InventoryItem[] EquipmentArray;
public bool AssignedLeft;
public bool AssignedRight;
public int ListInt;
public int InjuryListInt;
public int CrewRoleInt;
public bool AboveDeck;
public Ship AssignedShip;
public float TempHealth;
public List<float> PendingInjuries;
public List<string> InjuryList;
public float ProteinNutrition;
public float ProduceNutrition;
public float BeverageNutrition;
public float FoodSatiation;
public int AgeDays;
public Crew()
{
InjuryList = new List<string>();
CharacterStats = new List<float> { Cannoneering, Sailing, Ranged, Melee, Happiness, Health, Wage, Age };
//FoodHappinessAmounts = new float[ManagerItems.Instance.FoodBases.Count];
CurrentCharacterStats = new float[7];
CharacterStatProgress = new float[7];
int numSlots = System.Enum.GetNames(typeof(EquipmentSlot)).Length;
EquipmentArray = new InventoryItem[numSlots];
}
Re: Saved lists not functioning correctly
Hi there,
Would you also be able to send me the ES3Type you mentioned in your first post? This will let me know how they're being saved.
All the best,
Joel
Would you also be able to send me the ES3Type you mentioned in your first post? This will let me know how they're being saved.
All the best,
Joel
Re: Saved lists not functioning correctly
Here's the full code for the Ship ES3 type (Ship class contains the Crew Lists)
Here's the code where I reconstruct the lists (like I mentioned, I've tried both having all lists saved in the ES3 type and not, doesn't make a difference
Code: Select all
using System;
using UnityEngine;
namespace ES3Types
{
[UnityEngine.Scripting.Preserve]
[ES3PropertiesAttribute("CrewLists", "ShipInventoryInt", "ShipInventory", "BelowDeckInventory", "AboveDeckInventory", "BowInventory", "SternInventory", "AreaInventories", "AreaInventoriesTest", "CannonAmounts", "CurrentCargo", "MaxCargo", "CurrentCrew", "CurrentMaxCrew", "MaxCrew", "CurrentHullHP", "MaxHullHP", "CurrentSailsHP", "MaxSailsHP", "CannonballAmounts", "Draught", "Owner", "MaxCannonsBelowDeck", "MaxCannonsBow", "MaxCannonsStern", "MaxAreaCannons", "StabilityThresholdAboveDeck", "CannonManueverPenalty", "Armor", "ShipName", "ShipType", "ShipRole", "BaseInt", "FleetInInt", "Cannonballs", "MinimumSailingCrew", "MaximumSailingCrew", "MinimumMeleeCrew", "MaximumMeleeCrew", "MinimumCanoneerCrew", "MaximumCanoneerCrew", "MinimumMarksmanCrew", "MaximumMarksmanCrew", "CurrentCannonCrewAmount", "CurrentCannons", "CannonsCrewReq", "ShipPrice", "FleetInt", "CurrentSpeed", "CurrentMaxSpeed", "BaseMaxSpeed", "CurrentManeuver", "CurrentMaxManeuver", "BaseMaxManeuver", "DoChainShots", "DoGrapeShots", "CrewInjured", "CrewKilled", "Status", "Morale", "OfficerCount", "Strategy", "Aggression", "MarkedForCapture", "CannonCrewBoard", "MarksmanCrewBoard", "SailingCrewBoard", "NonMeleeCrewBoarding", "MinimumForCrewToBoard", "MaximumForCrewToBoard", "MedicineStrength", "OfficerLeadership", "OfficerNavalTactics", "OfficerNavigation", "OfficerMedicine", "OfficerCarpentry", "OfficerCooking", "OfficerStats", "AutoTrade", "ItemOrderInt", "StrengthRating", "ExcessCargo", "CannonManeueverPenalty", "ShipID")]
public class ES3UserType_Ship : ES3ObjectType
{
public static ES3Type Instance = null;
public ES3UserType_Ship() : base(typeof(Ship)){ Instance = this; priority = 1; }
protected override void WriteObject(object obj, ES3Writer writer)
{
var instance = (Ship)obj;
writer.WriteProperty("CrewLists", instance.CrewLists);
writer.WriteProperty("ShipInventoryInt", instance.ShipInventoryInt, ES3Type_int.Instance);
writer.WriteProperty("ShipInventory", instance.ShipInventory, ES3Type_Inventory.Instance);
writer.WriteProperty("BelowDeckInventory", instance.BelowDeckInventory, ES3Type_Inventory.Instance);
writer.WriteProperty("AboveDeckInventory", instance.AboveDeckInventory, ES3Type_Inventory.Instance);
writer.WriteProperty("BowInventory", instance.BowInventory, ES3Type_Inventory.Instance);
writer.WriteProperty("SternInventory", instance.SternInventory, ES3Type_Inventory.Instance);
writer.WriteProperty("AreaInventories", instance.AreaInventories);
writer.WriteProperty("AreaInventoriesTest", instance.AreaInventoriesTest);
writer.WriteProperty("CannonAmounts", instance.CannonAmounts);
writer.WriteProperty("CurrentCargo", instance.CurrentCargo, ES3Type_float.Instance);
writer.WriteProperty("MaxCargo", instance.MaxCargo, ES3Type_float.Instance);
writer.WriteProperty("CurrentCrew", instance.CurrentCrew, ES3Type_int.Instance);
writer.WriteProperty("CurrentMaxCrew", instance.CurrentMaxCrew, ES3Type_int.Instance);
writer.WriteProperty("MaxCrew", instance.MaxCrew, ES3Type_int.Instance);
writer.WriteProperty("CurrentHullHP", instance.CurrentHullHP, ES3Type_float.Instance);
writer.WriteProperty("MaxHullHP", instance.MaxHullHP, ES3Type_float.Instance);
writer.WriteProperty("CurrentSailsHP", instance.CurrentSailsHP, ES3Type_float.Instance);
writer.WriteProperty("MaxSailsHP", instance.MaxSailsHP, ES3Type_float.Instance);
writer.WriteProperty("CannonballAmounts", instance.CannonballAmounts);
writer.WriteProperty("Draught", instance.Draught, ES3Type_string.Instance);
writer.WriteProperty("Owner", instance.Owner, ES3Type_string.Instance);
writer.WriteProperty("MaxCannonsBelowDeck", instance.MaxCannonsBelowDeck, ES3Type_int.Instance);
writer.WriteProperty("MaxCannonsBow", instance.MaxCannonsBow, ES3Type_int.Instance);
writer.WriteProperty("MaxCannonsStern", instance.MaxCannonsStern, ES3Type_int.Instance);
writer.WriteProperty("MaxAreaCannons", instance.MaxAreaCannons);
writer.WriteProperty("StabilityThresholdAboveDeck", instance.StabilityThresholdAboveDeck, ES3Type_int.Instance);
writer.WriteProperty("CannonManueverPenalty", instance.CannonManueverPenalty, ES3Type_float.Instance);
writer.WriteProperty("Armor", instance.Armor, ES3Type_float.Instance);
writer.WriteProperty("ShipName", instance.ShipName, ES3Type_string.Instance);
writer.WriteProperty("ShipType", instance.ShipType, ES3Type_string.Instance);
writer.WriteProperty("ShipRole", instance.ShipRole, ES3Type_string.Instance);
writer.WriteProperty("BaseInt", instance.BaseInt, ES3Type_int.Instance);
writer.WriteProperty("FleetInInt", instance.FleetInInt, ES3Type_int.Instance);
writer.WriteProperty("Cannonballs", instance.Cannonballs);
writer.WriteProperty("MinimumSailingCrew", instance.MinimumSailingCrew, ES3Type_int.Instance);
writer.WriteProperty("MaximumSailingCrew", instance.MaximumSailingCrew, ES3Type_int.Instance);
writer.WriteProperty("MinimumMeleeCrew", instance.MinimumMeleeCrew, ES3Type_int.Instance);
writer.WriteProperty("MaximumMeleeCrew", instance.MaximumMeleeCrew, ES3Type_int.Instance);
writer.WriteProperty("MinimumCanoneerCrew", instance.MinimumCanoneerCrew, ES3Type_int.Instance);
writer.WriteProperty("MaximumCanoneerCrew", instance.MaximumCanoneerCrew, ES3Type_int.Instance);
writer.WriteProperty("MinimumMarksmanCrew", instance.MinimumMarksmanCrew, ES3Type_int.Instance);
writer.WriteProperty("MaximumMarksmanCrew", instance.MaximumMarksmanCrew, ES3Type_int.Instance);
writer.WriteProperty("CurrentCannonCrewAmount", instance.CurrentCannonCrewAmount, ES3Type_int.Instance);
writer.WriteProperty("CurrentCannons", instance.CurrentCannons, ES3Type_int.Instance);
writer.WriteProperty("CannonsCrewReq", instance.CannonsCrewReq, ES3Type_int.Instance);
writer.WriteProperty("ShipPrice", instance.ShipPrice, ES3Type_float.Instance);
writer.WriteProperty("FleetInt", instance.FleetInt, ES3Type_int.Instance);
writer.WriteProperty("CurrentSpeed", instance.CurrentSpeed, ES3Type_float.Instance);
writer.WriteProperty("CurrentMaxSpeed", instance.CurrentMaxSpeed, ES3Type_float.Instance);
writer.WriteProperty("BaseMaxSpeed", instance.BaseMaxSpeed, ES3Type_float.Instance);
writer.WriteProperty("CurrentManeuver", instance.CurrentManeuver, ES3Type_float.Instance);
writer.WriteProperty("CurrentMaxManeuver", instance.CurrentMaxManeuver, ES3Type_float.Instance);
writer.WriteProperty("BaseMaxManeuver", instance.BaseMaxManeuver, ES3Type_float.Instance);
writer.WriteProperty("DoChainShots", instance.DoChainShots, ES3Type_bool.Instance);
writer.WriteProperty("DoGrapeShots", instance.DoGrapeShots, ES3Type_bool.Instance);
writer.WriteProperty("CrewInjured", instance.CrewInjured, ES3Type_int.Instance);
writer.WriteProperty("CrewKilled", instance.CrewKilled, ES3Type_int.Instance);
writer.WriteProperty("Status", instance.Status, ES3Type_string.Instance);
writer.WriteProperty("Morale", instance.Morale, ES3Type_float.Instance);
writer.WriteProperty("OfficerCount", instance.OfficerCount, ES3Type_int.Instance);
writer.WriteProperty("Strategy", instance.Strategy, ES3Type_string.Instance);
writer.WriteProperty("Aggression", instance.Aggression, ES3Type_int.Instance);
writer.WriteProperty("MarkedForCapture", instance.MarkedForCapture, ES3Type_bool.Instance);
writer.WriteProperty("CannonCrewBoard", instance.CannonCrewBoard, ES3Type_bool.Instance);
writer.WriteProperty("MarksmanCrewBoard", instance.MarksmanCrewBoard, ES3Type_bool.Instance);
writer.WriteProperty("SailingCrewBoard", instance.SailingCrewBoard, ES3Type_bool.Instance);
writer.WriteProperty("NonMeleeCrewBoarding", instance.NonMeleeCrewBoarding);
writer.WriteProperty("MinimumForCrewToBoard", instance.MinimumForCrewToBoard);
writer.WriteProperty("MaximumForCrewToBoard", instance.MaximumForCrewToBoard);
writer.WriteProperty("MedicineStrength", instance.MedicineStrength, ES3Type_float.Instance);
writer.WriteProperty("OfficerLeadership", instance.OfficerLeadership, ES3Type_float.Instance);
writer.WriteProperty("OfficerNavalTactics", instance.OfficerNavalTactics, ES3Type_float.Instance);
writer.WriteProperty("OfficerNavigation", instance.OfficerNavigation, ES3Type_float.Instance);
writer.WriteProperty("OfficerMedicine", instance.OfficerMedicine, ES3Type_float.Instance);
writer.WriteProperty("OfficerCarpentry", instance.OfficerCarpentry, ES3Type_float.Instance);
writer.WriteProperty("OfficerCooking", instance.OfficerCooking, ES3Type_float.Instance);
writer.WriteProperty("OfficerStats", instance.OfficerStats);
writer.WriteProperty("AutoTrade", instance.AutoTrade, ES3Type_bool.Instance);
writer.WriteProperty("ItemOrderInt", instance.ItemOrderInt, ES3Type_int.Instance);
writer.WriteProperty("StrengthRating", instance.StrengthRating, ES3Type_float.Instance);
writer.WriteProperty("ExcessCargo", instance.ExcessCargo, ES3Type_float.Instance);
writer.WriteProperty("CannonManeueverPenalty", instance.CannonManeueverPenalty, ES3Type_float.Instance);
writer.WriteProperty("ShipID", instance.ShipID, ES3Type_int.Instance);
}
protected override void ReadObject<T>(ES3Reader reader, object obj)
{
var instance = (Ship)obj;
foreach(string propertyName in reader.Properties)
{
switch(propertyName)
{
case "CrewLists":
instance.CrewLists = reader.Read<System.Collections.Generic.List<System.Collections.Generic.List<Crew>>>();
break;
case "ShipInventoryInt":
instance.ShipInventoryInt = reader.Read<System.Int32>(ES3Type_int.Instance);
break;
case "ShipInventory":
instance.ShipInventory = reader.Read<Inventory>(ES3Type_Inventory.Instance);
break;
case "BelowDeckInventory":
instance.BelowDeckInventory = reader.Read<Inventory>(ES3Type_Inventory.Instance);
break;
case "AboveDeckInventory":
instance.AboveDeckInventory = reader.Read<Inventory>(ES3Type_Inventory.Instance);
break;
case "BowInventory":
instance.BowInventory = reader.Read<Inventory>(ES3Type_Inventory.Instance);
break;
case "SternInventory":
instance.SternInventory = reader.Read<Inventory>(ES3Type_Inventory.Instance);
break;
case "AreaInventories":
instance.AreaInventories = reader.Read<System.Collections.Generic.List<Inventory>>();
break;
case "AreaInventoriesTest":
instance.AreaInventoriesTest = reader.Read<System.Collections.Generic.List<System.Collections.Generic.List<InventoryItem>>>();
break;
case "CannonAmounts":
instance.CannonAmounts = reader.Read<System.Collections.Generic.List<System.Int32>>();
break;
case "CurrentCargo":
instance.CurrentCargo = reader.Read<System.Single>(ES3Type_float.Instance);
break;
case "MaxCargo":
instance.MaxCargo = reader.Read<System.Single>(ES3Type_float.Instance);
break;
case "CurrentCrew":
instance.CurrentCrew = reader.Read<System.Int32>(ES3Type_int.Instance);
break;
case "CurrentMaxCrew":
instance.CurrentMaxCrew = reader.Read<System.Int32>(ES3Type_int.Instance);
break;
case "MaxCrew":
instance.MaxCrew = reader.Read<System.Int32>(ES3Type_int.Instance);
break;
case "CurrentHullHP":
instance.CurrentHullHP = reader.Read<System.Single>(ES3Type_float.Instance);
break;
case "MaxHullHP":
instance.MaxHullHP = reader.Read<System.Single>(ES3Type_float.Instance);
break;
case "CurrentSailsHP":
instance.CurrentSailsHP = reader.Read<System.Single>(ES3Type_float.Instance);
break;
case "MaxSailsHP":
instance.MaxSailsHP = reader.Read<System.Single>(ES3Type_float.Instance);
break;
case "CannonballAmounts":
instance.CannonballAmounts = reader.Read<System.Collections.Generic.List<System.Int32>>();
break;
case "Draught":
instance.Draught = reader.Read<System.String>(ES3Type_string.Instance);
break;
case "Owner":
instance.Owner = reader.Read<System.String>(ES3Type_string.Instance);
break;
case "MaxCannonsBelowDeck":
instance.MaxCannonsBelowDeck = reader.Read<System.Int32>(ES3Type_int.Instance);
break;
case "MaxCannonsBow":
instance.MaxCannonsBow = reader.Read<System.Int32>(ES3Type_int.Instance);
break;
case "MaxCannonsStern":
instance.MaxCannonsStern = reader.Read<System.Int32>(ES3Type_int.Instance);
break;
case "MaxAreaCannons":
instance.MaxAreaCannons = reader.Read<System.Collections.Generic.List<System.Int32>>();
break;
case "StabilityThresholdAboveDeck":
instance.StabilityThresholdAboveDeck = reader.Read<System.Int32>(ES3Type_int.Instance);
break;
case "CannonManueverPenalty":
instance.CannonManueverPenalty = reader.Read<System.Single>(ES3Type_float.Instance);
break;
case "Armor":
instance.Armor = reader.Read<System.Single>(ES3Type_float.Instance);
break;
case "ShipName":
instance.ShipName = reader.Read<System.String>(ES3Type_string.Instance);
break;
case "ShipType":
instance.ShipType = reader.Read<System.String>(ES3Type_string.Instance);
break;
case "ShipRole":
instance.ShipRole = reader.Read<System.String>(ES3Type_string.Instance);
break;
case "BaseInt":
instance.BaseInt = reader.Read<System.Int32>(ES3Type_int.Instance);
break;
case "FleetInInt":
instance.FleetInInt = reader.Read<System.Int32>(ES3Type_int.Instance);
break;
case "Cannonballs":
instance.Cannonballs = reader.Read<System.Collections.Generic.List<InventoryItem>>();
break;
case "MinimumSailingCrew":
instance.MinimumSailingCrew = reader.Read<System.Int32>(ES3Type_int.Instance);
break;
case "MaximumSailingCrew":
instance.MaximumSailingCrew = reader.Read<System.Int32>(ES3Type_int.Instance);
break;
case "MinimumMeleeCrew":
instance.MinimumMeleeCrew = reader.Read<System.Int32>(ES3Type_int.Instance);
break;
case "MaximumMeleeCrew":
instance.MaximumMeleeCrew = reader.Read<System.Int32>(ES3Type_int.Instance);
break;
case "MinimumCanoneerCrew":
instance.MinimumCanoneerCrew = reader.Read<System.Int32>(ES3Type_int.Instance);
break;
case "MaximumCanoneerCrew":
instance.MaximumCanoneerCrew = reader.Read<System.Int32>(ES3Type_int.Instance);
break;
case "MinimumMarksmanCrew":
instance.MinimumMarksmanCrew = reader.Read<System.Int32>(ES3Type_int.Instance);
break;
case "MaximumMarksmanCrew":
instance.MaximumMarksmanCrew = reader.Read<System.Int32>(ES3Type_int.Instance);
break;
case "CurrentCannonCrewAmount":
instance.CurrentCannonCrewAmount = reader.Read<System.Int32>(ES3Type_int.Instance);
break;
case "CurrentCannons":
instance.CurrentCannons = reader.Read<System.Int32>(ES3Type_int.Instance);
break;
case "CannonsCrewReq":
instance.CannonsCrewReq = reader.Read<System.Int32>(ES3Type_int.Instance);
break;
case "ShipPrice":
instance.ShipPrice = reader.Read<System.Single>(ES3Type_float.Instance);
break;
case "FleetInt":
instance.FleetInt = reader.Read<System.Int32>(ES3Type_int.Instance);
break;
case "CurrentSpeed":
instance.CurrentSpeed = reader.Read<System.Single>(ES3Type_float.Instance);
break;
case "CurrentMaxSpeed":
instance.CurrentMaxSpeed = reader.Read<System.Single>(ES3Type_float.Instance);
break;
case "BaseMaxSpeed":
instance.BaseMaxSpeed = reader.Read<System.Single>(ES3Type_float.Instance);
break;
case "CurrentManeuver":
instance.CurrentManeuver = reader.Read<System.Single>(ES3Type_float.Instance);
break;
case "CurrentMaxManeuver":
instance.CurrentMaxManeuver = reader.Read<System.Single>(ES3Type_float.Instance);
break;
case "BaseMaxManeuver":
instance.BaseMaxManeuver = reader.Read<System.Single>(ES3Type_float.Instance);
break;
case "DoChainShots":
instance.DoChainShots = reader.Read<System.Boolean>(ES3Type_bool.Instance);
break;
case "DoGrapeShots":
instance.DoGrapeShots = reader.Read<System.Boolean>(ES3Type_bool.Instance);
break;
case "CrewInjured":
instance.CrewInjured = reader.Read<System.Int32>(ES3Type_int.Instance);
break;
case "CrewKilled":
instance.CrewKilled = reader.Read<System.Int32>(ES3Type_int.Instance);
break;
case "Status":
instance.Status = reader.Read<System.String>(ES3Type_string.Instance);
break;
case "Morale":
instance.Morale = reader.Read<System.Single>(ES3Type_float.Instance);
break;
case "OfficerCount":
instance.OfficerCount = reader.Read<System.Int32>(ES3Type_int.Instance);
break;
case "Strategy":
instance.Strategy = reader.Read<System.String>(ES3Type_string.Instance);
break;
case "Aggression":
instance.Aggression = reader.Read<System.Int32>(ES3Type_int.Instance);
break;
case "MarkedForCapture":
instance.MarkedForCapture = reader.Read<System.Boolean>(ES3Type_bool.Instance);
break;
case "CannonCrewBoard":
instance.CannonCrewBoard = reader.Read<System.Boolean>(ES3Type_bool.Instance);
break;
case "MarksmanCrewBoard":
instance.MarksmanCrewBoard = reader.Read<System.Boolean>(ES3Type_bool.Instance);
break;
case "SailingCrewBoard":
instance.SailingCrewBoard = reader.Read<System.Boolean>(ES3Type_bool.Instance);
break;
case "NonMeleeCrewBoarding":
instance.NonMeleeCrewBoarding = reader.Read<System.Collections.Generic.List<System.Boolean>>();
break;
case "MinimumForCrewToBoard":
instance.MinimumForCrewToBoard = reader.Read<System.Collections.Generic.List<System.Single>>();
break;
case "MaximumForCrewToBoard":
instance.MaximumForCrewToBoard = reader.Read<System.Collections.Generic.List<System.Single>>();
break;
case "MedicineStrength":
instance.MedicineStrength = reader.Read<System.Single>(ES3Type_float.Instance);
break;
case "OfficerLeadership":
instance.OfficerLeadership = reader.Read<System.Single>(ES3Type_float.Instance);
break;
case "OfficerNavalTactics":
instance.OfficerNavalTactics = reader.Read<System.Single>(ES3Type_float.Instance);
break;
case "OfficerNavigation":
instance.OfficerNavigation = reader.Read<System.Single>(ES3Type_float.Instance);
break;
case "OfficerMedicine":
instance.OfficerMedicine = reader.Read<System.Single>(ES3Type_float.Instance);
break;
case "OfficerCarpentry":
instance.OfficerCarpentry = reader.Read<System.Single>(ES3Type_float.Instance);
break;
case "OfficerCooking":
instance.OfficerCooking = reader.Read<System.Single>(ES3Type_float.Instance);
break;
case "OfficerStats":
instance.OfficerStats = reader.Read<System.Collections.Generic.List<System.Single>>();
break;
case "AutoTrade":
instance.AutoTrade = reader.Read<System.Boolean>(ES3Type_bool.Instance);
break;
case "ItemOrderInt":
instance.ItemOrderInt = reader.Read<System.Int32>(ES3Type_int.Instance);
break;
case "StrengthRating":
instance.StrengthRating = reader.Read<System.Single>(ES3Type_float.Instance);
break;
case "ExcessCargo":
instance.ExcessCargo = reader.Read<System.Single>(ES3Type_float.Instance);
break;
case "CannonManeueverPenalty":
instance.CannonManeueverPenalty = reader.Read<System.Single>(ES3Type_float.Instance);
break;
case "ShipID":
instance.ShipID = reader.Read<System.Int32>(ES3Type_int.Instance);
break;
default:
reader.Skip();
break;
}
}
}
protected override object ReadObject<T>(ES3Reader reader)
{
var instance = new Ship();
ReadObject<T>(reader, instance);
return instance;
}
}
public class ES3UserType_ShipArray : ES3ArrayType
{
public static ES3Type Instance;
public ES3UserType_ShipArray() : base(typeof(Ship[]), ES3UserType_Ship.Instance)
{
Instance = this;
}
}
}
Code: Select all
foreach (Faction faction in PlayerSaveScript.FactionList)
{
foreach (Fleet tempFleet in faction.FactionFleets)
{
foreach (Ship tempShip in tempFleet.FleetShips)
{
tempShip.AllCrew = new List<Crew>();
tempShip.SailingCrew = new List<Crew>(tempShip.CrewLists[0]) { };
tempShip.MeleeCrew = new List<Crew>(tempShip.CrewLists[1]) { };
tempShip.CannonCrew = new List<Crew>(tempShip.CrewLists[3]) { };
foreach(List<Crew> crewList in tempShip.CrewLists)
{
foreach(Crew crew in crewList)
{
tempShip.AllCrew.Add(crew);
}
}
}
}
}
Re: Saved lists not functioning correctly
Hi there,
Just to check, have you used Debug.Log to check that the items in the CrewLists List are correct? Also be aware that the items in the array will be saved by reference rather than by value.
Also note that only the CrewLists list is being saved. The other lists are not being saved.
All the best,
Joel
Just to check, have you used Debug.Log to check that the items in the CrewLists List are correct? Also be aware that the items in the array will be saved by reference rather than by value.
Also note that only the CrewLists list is being saved. The other lists are not being saved.
All the best,
Joel
Re: Saved lists not functioning correctly
Also just looking at your updated code, you seem to be assigning the loaded values incorrectly.
tempShip.AllCrew = new List<Crew>();
tempShip.SailingCrew = new List<Crew>(tempShip.CrewLists[0]) { };
tempShip.MeleeCrew = new List<Crew>(tempShip.CrewLists[1]) { };
tempShip.CannonCrew = new List<Crew>(tempShip.CrewLists[3]) { }; // This should be [2], not [3], as there will not be three lists in there.
All the best,
Joel
tempShip.AllCrew = new List<Crew>();
tempShip.SailingCrew = new List<Crew>(tempShip.CrewLists[0]) { };
tempShip.MeleeCrew = new List<Crew>(tempShip.CrewLists[1]) { };
tempShip.CannonCrew = new List<Crew>(tempShip.CrewLists[3]) { }; // This should be [2], not [3], as there will not be three lists in there.
All the best,
Joel
Re: Saved lists not functioning correctly
I've tried saving, then not saving and reconstructing the lists on load, and neither makes the lists work correctly. I did use Debug and the lists are correct.Joel wrote: ↑Tue Aug 18, 2020 6:00 pm Hi there,
Just to check, have you used Debug.Log to check that the items in the CrewLists List are correct? Also be aware that the items in the array will be saved by reference rather than by value.
Also note that only the CrewLists list is being saved. The other lists are not being saved.
All the best,
Joel
Wouldn't save by reference be what I would want to use? Since I'm trying to have just one instance of each Crew object just in different lists.
Joel wrote: ↑Tue Aug 18, 2020 6:01 pm Also just looking at your updated code, you seem to be assigning the loaded values incorrectly.
tempShip.AllCrew = new List<Crew>();
tempShip.SailingCrew = new List<Crew>(tempShip.CrewLists[0]) { };
tempShip.MeleeCrew = new List<Crew>(tempShip.CrewLists[1]) { };
tempShip.CannonCrew = new List<Crew>(tempShip.CrewLists[3]) { }; // This should be [2], not [3], as there will not be three lists in there.
All the best,
Joel
Sorry I was removing some lists to day and forgot to edit that, the lists are still not working at any of the indexes though.
Re: Saved lists not functioning correctly
Hi there,
Would you be able to create a basic script which I can drop into a scene to replicate this? It's hard for me to decouple what you've sent from your own logic at the moment, so I'm struggling to replicate your issue.
All the best,
Joel
Would you be able to create a basic script which I can drop into a scene to replicate this? It's hard for me to decouple what you've sent from your own logic at the moment, so I'm struggling to replicate your issue.
All the best,
Joel