While following a tutorial, I came across this unusual syntax which has to be some kind of shorthand, but I'm unfamiliar with it, so it makes no sense to me:
var x: int = [-1, 1][randi() % 2]
Can anyone explain this?
randi() returns a random integer, %2, change the value to 0 or 1 [-1, 1][randi() % 2] Randomly returns -1 and 1.
is that x will be initialized to a value of -1 or 1
In case it's not obvious, the first set of brackets is creating an array of two numbers ([-1, 1]). The second is referencing one of the numbers in the array. I can definitely see it being confusing at first glance.