0 votes

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

in Engine by (169 points)

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?

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.

1 Answer

0 votes

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):
by (3,955 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.