forum > Problem title array
-
Win john Aug 21 at 12:36
I know to declare an array:
var a:Array<Dynamic>=[....];
I am making a tile.I tried:class Map { public static var myMap:Array<Int>; public function new() { myMap = [ [1, 1, 1, 1, 1, 1, 1, 1], [1, 0, 0, 0, 0, 0, 0, 1], [1, 0, 1, 0, 0, 0, 0, 1], [1, 0, 0, 0, 0, 1, 0, 1], [1, 0, 0, 0, 0, 0, 0, 1], [1, 1, 1, 1, 1, 1, 1, 1] ]; } }
I get Array<Int> should be Int.
How to declare this array in haxe?
thanks -
John Plsek Aug 21 at 15:18
public static var myMap:Array<Array<Int>>;
-
However since it's a static var it scopes to the class not the instance so you don't need to define it in new ( each instance will effectively be redefining it to the same thing ), not sure what difference inline makes in this situation but maybe...
public static var myMap:Array<Array<Int>> = [ [1, 1, 1, 1, 1, 1, 1, 1], [1, 0, 0, 0, 0, 0, 0, 1], [1, 0, 1, 0, 0, 0, 0, 1], [1, 0, 0, 0, 0, 1, 0, 1], [1, 0, 0, 0, 0, 0, 0, 1], [1, 1, 1, 1, 1, 1, 1, 1] ];
If you only need 1 and 0 then Bool maybe better, but more typing :)
< Prev
| Page 1 / 1 |
Next >