ello,
I’m just trying to knock up in Unity an old game it did ages ago. At the moment for speed I’m just working on the MAC, but plan on moving it to iPad when finished so I’m using the #pragma strict command just to make sure that what I do will work on iOS (thats correct so far?).
I’ve got a problem where if I use #pragma strict I get the following error: ‘>’ cannot be used with a left side of type’Object’ and a right hand side of type ‘int’
If I don’t use #pragma strict, it works fine.
//Generate Mines
for(i=0; i<((level*5)+5); i++){
objectPlacement =Random.Range((column*3),(totalGridSize-column));//RND number missing the top 3 rows off and the bottom row off
if (board[objectPlacement] >0) { //Error on this line
i=i-1;//If there's already something there, jump back a step and it will try again
}
if (board[objectPlacement]==0) {
board[objectPlacement]=2;//Place a mine here
}
}//End of Mine placement
So my question is how do I do the above line of code without removing the #pragma strict (making sure it will work on iOS devices)?
I’ve also tried !=0 (instead of >0) and got the same error.
I don’t want to do a loop checking each value one at a time as that just seems really poor, but I’m stuck and it’s really annoying me now =(
Any help please?
Hi tonyd,
Thanks for that. After a fair bit of playing around I’ve got it to work.
At first, I had it set up as
var board = new Array(totalGridSize);
But after reading that post (I’ve read so much about different ways of doing Arrays and 2D arrays I don’t know if I’m coming or going) I’ve set it up as follows and it seems to work.
static public var board: int [];//Create an array for the board
board=new int [row*column];
Thanks again for all your help.
Now on to the next bit of the game
Mike.
If you need dynamically-sized arrays, use List. You would pretty much never use the JS Array class. (Only if you were mixing different types in the same array, but realistically, how often do you need to do something like that?)
The game is pretty much turn based so speed isn’t an issue and played on a board so the array will stay the same size. Originally wanted to use 2D array’s but couldn’t work out a way to do that with JS on iOS so went with one large array and % and / the array to get the X and Y positions which works well enough for me.
I guess it’s just the normal learning curve I’m going through (only understanding half the stuff I read doesn’t help much, but I’m learning), but it’s fun so far =)
The other Unity users really are great for helping out and I wouldn’t get anywhere without that help which I’m really thankful for and hope I’ll be able to help out other users down the line.