- Home /
Array element to variable
Hello,
I have created an array by the following way:
var config = new Array();
var ind : int = 0;
sr = new File.OpenText(configPath);
input = "";
while (true)
{
input = sr.ReadLine();
if (input == null)
{
break;
}
config.Push(input);
}
The array is filled with integers. How can I assign the value of the third element to a variable? I have tried the following way, but it gives me a "Cannot cast from source type to destination type." error.
var volume : int = config[2];
Any ideas how should I do it?
Answer by Eric5h5 · Nov 16, 2011 at 04:49 PM
The array is filled with integers.
It's not, it's filled with strings. Anyway, use List instead of Array, and convert the strings to integers.
var config = new List.<int>();
...
config.Add(parseInt(input));
Your answer
Follow this Question
Related Questions
Bulletin Array, change element variables 1 Answer
Getting info from object within an array 1 Answer
How to delete a element from mesh rendered and mesh collider. 1 Answer
type ...Material[] vs Material (materials change at run time) 1 Answer
How to change all material elements of object's children 3 Answers