Davaris Posted July 10, 2010 Share Posted July 10, 2010 public override string ToString() { return string.Format("X:{0} Y:{1} Z:{2}", this.X, this.Y, this.Z); } public static Vector3 Parse(string value) { string[] values = value.Split(','); return new Vector3(float.Parse(values[0]), float.Parse(values[1]), float.Parse(values[2])); } The Parse function above is looking for ',' which doesn't exist. Here is the fix: public static Vector3 Parse(string value) { char[] delimiterChars = { 'X', 'Y', 'Z', ':', ' ' }; string[] values = value.Value.Split(delimiterChars, StringSplitOptions.RemoveEmptyEntries); return new Vector3(float.Parse(values[0]), float.Parse(values[1]), float.Parse(values[2])); } Quote Win 7 Pro 64 bit AMD Phenom II X3 720 2.8GHz GeForce 9800 GTX/9800 GTX+ 4 GB RAM Link to comment Share on other sites More sharing options...
L B Posted July 10, 2010 Share Posted July 10, 2010 Although the Vector classes are currently being rewritten by Tyler, I doubt it was meant to be used this way. A ToString is not necessarily an opposite to a Parse. Parse would Parse from the SBX in this comma separated way. IF anything was to change, it would be the ToString, not the Parse. Which would lead us to: public override string ToString() { return string.Format("{0},{1},{2}", this.X, this.Y, this.Z); } Quote Link to comment Share on other sites More sharing options...
Canardia Posted July 10, 2010 Share Posted July 10, 2010 SBX can have "," or " " as separator, depending on the engine version (2.2x vs 2.3x). Quote ■ Ryzen 9 ■ RX 6800M ■ 16GB ■ XF8 ■ Windows 11 ■ ■ Ultra ■ LE 2.5 ■ 3DWS 5.6 ■ Reaper ■ C/C++ ■ C# ■ Fortran 2008 ■ Story ■ ■ Homepage: https://canardia.com ■ Link to comment Share on other sites More sharing options...
TylerH Posted July 10, 2010 Share Posted July 10, 2010 We could have a FromString command that would take in the same format as is created with ToString, since it can be confusing, and them ofcourse have Parse to handle the actual engine-way of doing it. The idea is that Parse is taking a working string, ToString is creating a super pretty string to use in message boxes, logs, etc. They are usually not the same, but we could accommodate both for both casting to and parsing from. Quote nVidia 530M Intel Core i7 - 2.3Ghz 8GB DDR3 RAM Windows 7 Ultimate (64x)----- Visual Studio 2010 Ultimate Google Chrome Creative Suite 5 FL Studio 10 Office 15 ----- Expert Professional Expert BMX Programmer ----- Link to comment Share on other sites More sharing options...
Canardia Posted July 10, 2010 Share Posted July 10, 2010 Why don't you do it like in gamelib, there you have as default separator whatever is in the current engine, and optionally you can specify as 2nd parameter a different separator. Quote ■ Ryzen 9 ■ RX 6800M ■ 16GB ■ XF8 ■ Windows 11 ■ ■ Ultra ■ LE 2.5 ■ 3DWS 5.6 ■ Reaper ■ C/C++ ■ C# ■ Fortran 2008 ■ Story ■ ■ Homepage: https://canardia.com ■ Link to comment Share on other sites More sharing options...
Davaris Posted July 10, 2010 Author Share Posted July 10, 2010 IF anything was to change, it would be the ToString, not the Parse. Which would lead us to: public override string ToString() { return string.Format("{0},{1},{2}", this.X, this.Y, this.Z); } As long as it works in XML, that's fine by me. I am using what I assume is ToString to save and Parse when I'm loading. This is how I'm using it: // Saving XElement entry_list = header.Element("Entries"); entry_list.Add(new XElement("Entry", new XElement("Key", entry.Key), new XElement("Value", entry.Value), new XElement("Type", entry.Value.GetType().Name))); // Loading XElement key = x.Element("Key"); XElement value = x.Element("Value"); XElement type = x.Element("Type"); switch (type.Value) { case "String": mCurrSD.Put<string>(key.Value, (string)value.Value); break; case "Boolean": mCurrSD.Put<bool>(key.Value, bool.Parse(value.Value)); break; case "Int32": mCurrSD.Put<int>(key.Value, int.Parse(value.Value)); break; case "Single": mCurrSD.Put<float>(key.Value, float.Parse(value.Value)); break; case "Vector3": mCurrSD.Put<Leadwerks.Vector3>(key.Value, Leadwerks.Vector3.Parse(value.Value)); break; } Quote Win 7 Pro 64 bit AMD Phenom II X3 720 2.8GHz GeForce 9800 GTX/9800 GTX+ 4 GB RAM Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.