- Home /
Multidimensional .net array problem
Hi, i'm quite new with unity and ran into a problem with multidimensional .net arrays (unityscript).
var myArray : byte[,];
myArray = new byte[5,5];
myArray[0,0]=1;
myArray[1,0]=1;
...
I get the compiler error ArgumentException: not a widening conversion
Can someone explain to me, whats wrong here?
UPDATE:
the problem only seems to occur when using byte as variabletype. Int, String and double work fine and compile without an error.
Answer by Senhor de todo o Mal · Jun 09, 2011 at 08:58 AM
I compiled that code and I didn't get an error, but it does give that error at runtime.
If you try assigning a larger value than 255 to a byte you will get an error, also when you're using ints or larger will have to cast to byte.
Since there is no casting operator in UnityScript, here's what you can do:
var chunkArray : byte[,] = new byte[5,5]; //declare and initialize array
var bt:byte = 1; //cast to byte
chunkArray[0,0] = bt; //assign value
Thanks. I'll have to read on that to understand the solution but it solves the problem.
Your answer
Follow this Question
Related Questions
Multidimensional GameObject Arrays 1 Answer
Trouble with 2D Array for board game 3 Answers
Building a multidimensional array for grid movement. 2 Answers
trouble with 2 dimensional arrrays in javascript 1 Answer
Sweeping trough a 2D Color array 2 Answers