How Can I Use Range () for a Boolean Array?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By lucasfazzi

So I have an array that is a bunch of false results, and instead of putting that bunch of [false, false, false, false, false …] I would like to know if there is any method for me to turn this as a numeric array using range (); something like array = [false].range (30)?

thanks, folks

Your question doesn’t really make sense. You have an array already with a bunch of booleans in it, but what are you trying to do with it? What do you want the result to be?

kidscancode | 2019-11-27 02:08

To tell the truth, sometimes just write the doubt to note how stupid it sounds. You’re absolutely right, KCC, my question is completely pointless.

I was making my player interact with the game keys; basically an array keys = [false, false, false, false] and each time the player took a key from the map, it would turn one of the array values ​​to true and so on until all keys == true total, freeing a port.

but if I do with a numeric VAR it’s easier, better and faster, just by considering the total number of keys as a value and decreasing -1 for each key collected, until the VAR is zero and open the door, or anything in this sense.

Thanks a lot anyway, KCC, you helped clear my thoughts.

lucasfazzi | 2019-11-27 02:48

:bust_in_silhouette: Reply From: Dlean Jeans

In Python you can do: [False] * 30. Although GDScript is similar to Python, unfortunately it’s only syntactically.

So the shortest way I can think of in GDScript:

var array = []
for i in range(30):
	array.append(false)