Accessing a variable... return incorrect value.

Hey folks,

So I'm making save/load for a game I'm working on. Now I run into a weird (yet simple?) problem and I'm about to tear my hair off. Long story short, I'm taking an Array of digits(0-9), make a String out of it, save, load, cut back to digit and reset the Array. Then I'm accessing it using:

var myNewVar:int = GameObject.Find("MyObject").GetComponent("myScript").myArray[index];

Before I save/load, everything's fine. Once I've went through a save/load, both prints will still indicate the correct value(1). Printing MyNewVar now returns 49. I'm pretty confident nothing else is messing with our values. I'm also not adding the save/load function as it seems irrelevant, the Array is correct both before and after. In resume, my problem look like this:

var myArray = new Array(1,2,3);
print(myArray[0]); // = 1
var myVar:int = myArray[0];
print(myVar); // = 49 ???
print(myArray[0]); // = 1

Any help/hints/tips is welcome. BTW, I know about the inneficiency of the .Find, just trying to get it to work, first :)

I think it's working fine, but your test is making it look wrong.

You're saving as a string, so getting chars back for your array. `myArray` is really ('1','2','3').

49 is the ASCII value of `1`. For example, `var x:int = 'a';` should give you 97. If you used `var myVar:char`, you'd probably see the '1'.

Any of the standard "ConvertStringToInt" routines know about this, so you can just combine all of your "letters" and Convert to the correct number.