Hey guys, I ran into a problem;
Format Exception: Input string was not in the correct format
FormatException: Input string was not in the correct format
System.Int32.Parse (System.String s) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System/Int32.cs:629)
I am using a fairly simple save/load function that ‘encrypts’ and decodes a code to load a ship Not exactly sure what the problem is but I am fairly sure that int just doesn’t support a high enough value.
Just not sure how to fix it
I dont have any idea of a more efficient encryption as it has the bare minimum details
‘BlockId(x,y,z(x,y,z|’
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Text;
using System.Runtime.Serialization.Formatters.Binary;
using System.IO;
using System;
public class GameManager : MonoBehaviour {
public GameObject Base_Block;
public GameObject ship;
[Serializable]
class shipStringc{
public string ship;
}
//id,position(xyz),rotation(xyz)
public string shipString = "x(0,0,0(0,0,0|";
public void saveBuild(){
BinaryFormatter bf = new BinaryFormatter ();
FileStream file = File.Create (Application.persistentDataPath + "/shipBuilds.dat");
shipStringc data = new shipStringc ();
data.ship = shipString;
bf.Serialize (file, data);
file.Close ();
Debug.Log ("Saved!");
}
public void addBlock(int id, Vector3 pos, Quaternion rotation){
StringBuilder sb = new StringBuilder ();
sb.Append(id).Append("(").Append (pos.x).Append(",").Append (pos.y).Append(",").Append (pos.z).Append("(").Append (rotation.x).Append(",").Append (rotation.y).Append(",").Append (rotation.z);
shipString = shipString + sb.ToString () + "|";
}
private string shipToLoad;
public void loadBuild(){
this.transform.GetComponent<BuildManager> ().clearBuild ();
if (File.Exists (Application.persistentDataPath + "/shipBuilds.dat")) {
BinaryFormatter bf = new BinaryFormatter ();
FileStream file = File.Open (Application.persistentDataPath + "/shipBuilds.dat", FileMode.Open);
shipStringc data = (shipStringc)bf.Deserialize (file);
file.Close ();
shipToLoad = data.ship;
}
if (shipToLoad != null) {
shipToLoad = shipToLoad.Substring (0, shipToLoad.Length - 1);
string[] blockList = shipToLoad.Split('|');
foreach (string s in blockList) {
string[] sector = s.Split ('(');
string[] vectors = sector[1].Split (',');
string[] quaters = sector[2].Split (',');
if (sector [0] != "x") {
GameObject block = Instantiate (this.transform.GetComponent<BlockList> ().Blocks [int.Parse (sector [0])].BlockObj,
new Vector3 ((int.Parse (vectors [0])), (int.Parse (vectors [1])), (int.Parse (vectors [2]))),
new Quaternion ((int.Parse (quaters [0])), (int.Parse (quaters [1])), (int.Parse (quaters [2])), 0));
block.transform.parent = ship.transform;
} else {
}
}
}
}
}