Hi All, I have created a Vector 2 and have a multdimensional array. I am then grabbing the x and y values of the Vector2 to perform a lookup in the Array. The problem is, it only half works and/or gives me an error. Can anyone see if I am doing something wrong or not doing something correct or is this some sort of issue? Here is a rough example of what I am doing: Code (csharp): var grid = new Array(); grid.Push(new Array(1,1,1,1)); grid.Push(new Array(1,1,1,1)); grid.Push(new Array(1,1,1,1)); var tester = Vector2(2,2); print (gridMap[tester.x][tester.y]); There error I am getting is: ArgumentException: parameters Boo.Lang.RuntimeServices.GetSlice(System.Object target, System.String name, System.Object[] args) [0x00000] The half works part is I can use either .x or .y to get the front part of the array but using both in combination gives me the error. In fact, I can even use the .x or .y and then use a number as the second accessor and it will work. Thanks in advance for the help. Regards, -- Clint
Vector2.x is of type float and not int. Floats can't be used to index arrays. Instead you can use use an int.
I understand that it shouldn't work but it does for the first portion of it. For example: Code (csharp): var tester = Vector2(2,2); print (gridMap[tester.x]); That will return the proper item. So maybe this is something that should be checked when compiled? Also, how do I do an inline float to integer conversion? In normal Javascript I could use parseInt, parseFloat and some others but those give me an error... I have tried Number, Integer, etc. and those all throw errors as well... So as an example this is what I am doing when trying that conversion: Code (csharp): var tester = Vector2(2,2); print (gridMap[Integer(tester.x)]); or print (gridMap[Number(tester.x)]); or print (gridMap[parseInt(tester.x)]); Thanks! -- Clint
You can do conversion to int like this. We are going to add parseInt and parseFloat with the next release. Code (csharp): var grid = new Array(); grid.Push(new Array(1,1,1,1)); grid.Push(new Array(1,1,1,1)); grid.Push(new Array(1,1,1,1)); var tester = Vector2(2,2); function Start () { var testerXInt : int = tester.x; var testerYInt : int = tester.y; print (grid[testerXInt][testerYInt]); }