Oh yes that all makes sense. Kind of. But now I see no conceivable advantage of using classes for this except for, like, Class functions…
I didn’t want to have to do this, but here is my original Save/Load code (Check out lines 22, and line 72-90)
I know it looks complicated, but I’m simply piling the Guns array into a string, and then loading it by splitting it using a For loop and loading it into an array. From there, would I assign all of these gun variables to separate Objects (i.e Machine, Classic, Ray, etc) of class Gun?
/*This script will keep track of all universally accessible variables.
It will also keep track of save data in the form of arrays and
will be referenced each time a game is saved / loaded*/
//The beginning of this script will be the save and slot-independent variables that need to be accessed more than the others.
static var CurrentSlot : int;
static var GameStage : int;
//GameStage works like so: Main Menu = 1, Garage = 2, In Flight = 3, Boss Battle = 4, Game Over = 5, Credits =6, Tutorial = 7
/*And now we begin the save stuff
SLOT ONE IS INDEXED AS 0, SLOT 2 IS 1, AND SLOT 3 IS 2*/
//The name variable
static var Name : String;
//The Color variable
static var Col : Color;
//the Ore number
static var Ore : int;
//Keeps track of the unlocked specials (1 = unlocked, 0 = locked)
static var Specials = new int[6];
//Now onto creating the Ship upgrade variables and their respective arrays
static var ShipUps : int[] = new int[4];
//Time for the guns
static var Guns : int[,] = new int[8,7];
//Functions
function Awake(){
GameStage = 1;
}
//Save Function
static function SaveSlot(){
var SaveStr = (Name + "|" + Ore + "|" + Specials + "|" + ShipUps + "|" + Guns).ToString();
PlayerPrefs.SetString("Slot"+CurrentSlot, SaveStr);
PlayerPrefsX.SetColor("Color" + CurrentSlot, Col);
PlayerPrefs.Save();
//Load Function
}
static function LoadSlot(){
var LoadStr = PlayerPrefs.GetString("Slot"+CurrentSlot);
//Splitting
var LoadArr = LoadStr.Split("|"[0]);
//Loading Name
Name = LoadArr[0];
Debug.Log("Loaded Name as " + Name);
//Loading the color
Col = PlayerPrefsX.GetColor("Color" + CurrentSlot);
Debug.Log("Loaded Color as " + Col );
//Loading Ore
Ore = parseInt(LoadArr[1]);
Debug.Log("Loaded Ore as " + Ore);
//Splitting up the Specials String
var SpecStr = LoadArr[2];
for(i=0; i < SpecStr.length; i++){
var SpecAdd = parseInt(SpecStr.Substring(i,1));
Specials[i] = SpecAdd;
}
Debug.Log("Loaded Specials as " + "[ " + Specials[0] + " , " +Specials[1] + " , " +Specials[2] + " , " +Specials[3] + " , " +Specials[4] + " , " +Specials[5] + " ]");
//End Splitting up Specials String
//Splitting up ShipUpgrades string
var ShipStr = LoadArr[3];
for(s=0; s < ShipStr.length; s++){
var ShipAdd = parseInt(ShipStr.Substring(s,1));
ShipUps[s] = ShipAdd;
}
Debug.Log("Loaded Ship Upgrades as " + "[ " + ShipUps[0] + " , " + ShipUps[1] + " , " + ShipUps[2] + " , " + ShipUps[3] + " ]");
//End Splitting ShipUpgrades String
//Splitting up THE GUNS, BITCHES
var GunStr = LoadArr[4];
//First Layer (Divided into 7 parts)
for(g=0; g < 8; g++){
//Second Layer
for(p=0; p< 7; p++){
var GunAttrAdd = parseInt(GunStr.Substring(((g*7)+(p)),1));
Guns[g,p] = GunAttrAdd;
}
}
Debug.Log("Loaded Classic Stats as " + "Plasma Drain: Level " + Guns[0,0]+ ", " + "Plasma Recharge: Level " + Guns[0,1]+ ", " + "Energy Drain: Level " + Guns[0,2] + ", " + "Damage: Level" + Guns[0,3] + ", " + "Special: Level " + Guns[0,4] + ", " + "Unlocked (1/0): " + Guns[0,5] + ", " + "Equipped (0 = no, 1,2,3): " + Guns[0,6]);
Debug.Log("Loaded Machine Stats as " + "Plasma Drain: Level " + Guns[1,0]+ ", " + "Plasma Recharge: Level " + Guns[1,1]+ ", " + "Energy Drain: Level " + Guns[1,2] + ", " + "Damage: Level" + Guns[1,3] + ", " + "Special: Level " + Guns[1,4] + ", " + "Unlocked (1/0): " + Guns[1,5] + ", " + "Equipped (0 = no, 1,2,3): " + Guns[1,6]);
Debug.Log("Loaded BFG Stats as " + "Plasma Drain: Level " + Guns[2,0]+ ", " + "Plasma Recharge: Level " + Guns[2,1]+ ", " + "Energy Drain: Level " + Guns[2,2] + ", " + "Damage: Level" + Guns[2,3] + ", " + "Special: Level " + Guns[2,4] + ", " + "Unlocked (1/0): " + Guns[2,5] + ", " + "Equipped (0 = no, 1,2,3): " + Guns[2,6]);
Debug.Log("Loaded Whip Stats as " + "Plasma Drain: Level " + Guns[3,0]+ ", " + "Plasma Recharge: Level " + Guns[3,1]+ ", " + "Energy Drain: Level " + Guns[3,2] + ", " + "Damage: Level" + Guns[3,3] + ", " + "Special: Level " + Guns[3,4] + ", " + "Unlocked (1/0): " + Guns[3,5] + ", " + "Equipped (0 = no, 1,2,3): " + Guns[3,6]);
Debug.Log("Loaded Ray Stats as " + "Plasma Drain: Level " + Guns[4,0]+ ", " + "Plasma Recharge: Level " + Guns[4,1]+ ", " + "Energy Drain: Level " + Guns[4,2] + ", " + "Damage: Level" + Guns[4,3] + ", " + "Special: Level " + Guns[4,4] + ", " + "Unlocked (1/0): " + Guns[4,5] + ", " + "Equipped (0 = no, 1,2,3): " + Guns[4,6]);
Debug.Log("Loaded Spray Stats as " + "Plasma Drain: Level " + Guns[5,0]+ ", " + "Plasma Recharge: Level " + Guns[5,1]+ ", " + "Energy Drain: Level " + Guns[5,2] + ", " + "Damage: Level" + Guns[5,3] + ", " + "Special: Level " + Guns[5,4] + ", " + "Unlocked (1/0): " + Guns[5,5] + ", " + "Equipped (0 = no, 1,2,3): " + Guns[5,6]);
Debug.Log("Loaded Spear Stats as " + "Plasma Drain: Level " + Guns[6,0]+ ", " + "Plasma Recharge: Level " + Guns[6,1]+ ", " + "Energy Drain: Level " + Guns[6,2] + ", " + "Damage: Level" + Guns[6,3] + ", " + "Special: Level " + Guns[6,4] + ", " + "Unlocked (1/0): " + Guns[6,5] + ", " + "Equipped (0 = no, 1,2,3): " + Guns[6,6]);
Debug.Log("Loaded Wave Stats as " + "Plasma Drain: Level " + Guns[7,0]+ ", " + "Plasma Recharge: Level " + Guns[7,1]+ ", " + "Energy Drain: Level " + Guns[7,2] + ", " + "Damage: Level" + Guns[7,3] + ", " + "Special: Level " + Guns[7,4] + ", " + "Unlocked (1/0): " + Guns[7,5] + ", " + "Equipped (0 = no, 1,2,3): " + Guns[7,6]);
}