- Home /
Initialize boolean array as all true Unity JS
How do I Initialize boolean array as all true in JS .. ?
public var terroristShooting : boolean[] = new boolean[10];
Answer by whydoidoit · Oct 09, 2012 at 07:26 PM
A for next loop really would be the fastest - I haven't tested it but you could probably do it with Linq:
import System.Linq;
var terroristShooting = Enumerable.Range(0,10).Select(function(c) true).ToArray();
For some strange reason it didn't work then I seen your reply and tried again .. again it did not work print was outputting false to the console so I saved and closed unity and monodevelop and restarted them with nothing changed and ran it again, this time it worked outputting true to the console, strange, I'm using Unity 4 ..
Odd - 3.5.6 for me. It ought to work always - but there you go...
Answer by Eric5h5 · Oct 09, 2012 at 07:34 PM
for (var ts in terroristShooting) ts = true;
If you do it a lot, you could make your own function which makes a boolean array and fills it with true:
public var terroristShooting : boolean[] = BooleanArrayTrue(10);
function BooleanArrayTrue (size : int) : boolean[] {
var boolArray = new boolean[size];
for (var b in boolArray) b = true;
return boolArray;
}
Your answer
Follow this Question
Related Questions
question about array or list of boolean 1 Answer
Boolean while looking at a game object? 1 Answer
Boolean doesn't become true 2 Answers
The public bool will not change unless i set it 1 Answer
Array SetActive C# Unity 1 Answer