- Home /
Type 'Object' does not support slicing.
Dear all, I am new to javaScript so please excuse my question if I am just missing something really simple. I have searched all over the net for answers but I can't seem to decipher exactly what is going wrong. The error I am getting is 'BCE0048: Type 'Object' does not support slicing.' but only when I try to build to iOS.
I found and read:
How to declare and initialize multidimensional arrays JS?
BCE0048 type Object does not support slicing
Type Object does not support slicing Unity3D
But I don't seem to be any closer to working out what's wrong. I think it might be something to do with "not typing my variables" but can't seem to work out how to do this using my current array setup. After trying many different combination and getting very frustrated, I finally decided to try posting on here. Any help much appreciated.
Code:
var zoneString = new Array ();
var zoneMoves = new Array ();
zoneMoves[0] = new Array ([
[0,0,0],
[0,0,0],
[0,0,0],
[0,0,0],
[0,0,0]
]);
zoneMoves[1] = new Array ([
[0,1,0],
[0,0,1],
[0,1,0],
[0,0,1],
[0,1,0]
]);
function Start () {
zoneString[1] = new Array (zoneMoves[1][0][0].ToString() + zoneMoves[1][0][1].ToString() + zoneMoves[1][0][2].ToString());
}
function Update () {
}
The best thing to do is not ever use the JS Array class. Use built-in arrays, or List.
Answer by ThermalFusion · Sep 01, 2012 at 10:24 PM
#pragma strict
public class ZoneMoves extends MonoBehaviour {
//var zoneString = new Array ();
private var zoneString : String[];
//var zoneMoves = new Array ();
private var zoneMoves : int [,,];
function Awake() {
zoneString = new String[3];
zoneMoves = new int[2,5,3];
//zoneMoves[0] = new Array ([
//[0,0,0],
zoneMoves[0,0,0] = 0;
zoneMoves[0,0,1] = 0;
zoneMoves[0,0,2] = 0;
//[0,0,0],
zoneMoves[0,1,0] = 0;
zoneMoves[0,1,1] = 0;
zoneMoves[0,1,2] = 0;
//[0,0,0],
zoneMoves[0,2,0] = 0;
zoneMoves[0,2,1] = 0;
zoneMoves[0,2,2] = 0;
//[0,0,0],
zoneMoves[0,3,0] = 0;
zoneMoves[0,3,1] = 0;
zoneMoves[0,3,2] = 0;
//[0,0,0],
zoneMoves[0,4,0] = 0;
zoneMoves[0,4,1] = 0;
zoneMoves[0,4,2] = 0;
//]);
//zoneMoves[1] = new Array ([
//[0,1,0],
zoneMoves[1,0,0] = 0;
zoneMoves[1,0,1] = 1;
zoneMoves[1,0,2] = 0;
//[0,0,1],
zoneMoves[1,1,0] = 0;
zoneMoves[1,1,1] = 0;
zoneMoves[1,1,2] = 1;
//[0,1,0],
zoneMoves[1,2,0] = 0;
zoneMoves[1,2,1] = 1;
zoneMoves[1,2,2] = 0;
//[0,0,1],
zoneMoves[1,3,0] = 0;
zoneMoves[1,3,1] = 0;
zoneMoves[1,3,2] = 1;
//[0,1,0],
zoneMoves[1,4,0] = 0;
zoneMoves[1,4,1] = 1;
zoneMoves[1,4,2] = 0;
//]);
}
function Start () {
//zoneString[1] = new Array (zoneMoves[1][0][0].ToString() + zoneMoves[1][0][1].ToString() + zoneMoves[1][0][2].ToString());
zoneString[1] = zoneMoves[1,0,0].ToString() + zoneMoves[1,0,1].ToString() + zoneMoves[1,0,2].ToString();
Debug.Log(zoneString[1]);
}
function Update () {
}
}
Thank you for your reply. However I still cannot solve the slicing problem. I have read everything under the supplied link, regarding 'Use Builtin arrays' I have added the '#pragma strict' line at the top. And I have tried many combinations:
var zoneString : Array = new Array (); var zone$$anonymous$$oves : Array = new Array ();
var zoneString : String[]; var zone$$anonymous$$oves : int[];
zone$$anonymous$$oves[0] = new int ([ [0,0,0], [0,0,0], ]);
I just get the slicing error in the Start function.
var zoneString = new Array ();
var zone$$anonymous$$oves : int[,,] = new int[3,3,3];
function Start () {
zoneString[1] = new Array (zone$$anonymous$$oves[1,1,1].ToString() + zone$$anonymous$$oves[1,0,1].ToString() + zone$$anonymous$$oves[1,0,2].ToString());
}
You can do multidimensional arrays like this.
Ok, thanks.. now I am getting [BCE0109: Array 'self.zone$$anonymous$$oves' is rank '3', not rank '1'.] In line: zone$$anonymous$$oves[0] = new Array ([ [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0] ]);
You have to set the [0,0,0] in a different way using multidimensional arrays like in the above comment. zone$$anonymous$$oves[0,0,0] = 2; zone$$anonymous$$oves[0,0,1] = 3; zone$$anonymous$$oves[0,0,2] = 4;
I need my original code to work in the same way but on iOS. It is very important the each [zone$$anonymous$$oves] is laid out in the same way as my first post. It is the group of 15 positions that equals one triggered move stored under an array ID. The grouping of rows of three is a visual representation of how the elements are laid out in the game.
Could someone duplicate my code above and fix it so it compiles for iOS please?
Your answer
Follow this Question
Related Questions
Javascript remove object from array. 0 Answers
Turn all objects in the array to make same thing 0 Answers
InvalidCastException error and logic error 1 Answer
Store an array inside of an array 1 Answer