0 votes

I want to check if all variables (which are booleans) in an array are true or false.

EG. (VERY basic and stripped down pseudo code just meant to get the point across)

var array = [x, y, z]

func onClick():
    array[0] = false #x to false
    array[1] = false #y to false
    array[2] = false #z to false

func _process(delta):
    if all of array is false:

Thank you in advance.

Godot version version 3.4
in Engine by (58 points)
If array[0] == false and array[1] == false and array[2] == false:
   do whatever

Is there not a more efficient way to do this? I am aware of this, but I want to check for ALL at the same time and if they ARE all false then it will do something.

1 Answer

+4 votes
Best answer

You can also use the in operator for that:

if not false in array:
    print("All entries are true")
by (1,519 points)
selected by

I didn't know this was legal

Awesome, thank you so much!
This will be very useful.

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 Frequently asked questions and 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 [email protected] with your username.