Check multiple conditions for the same value in If statements

Godot Version

4.2.1.stable

Question

Hello! Is there a way to make this:
if a == 1 && b == 1 && c == 1 && d == 1:
become something* like this:
if a&&b&&c&&d == 1:
*but not grouping them in strings, arrays or anything.

Imagine I have 50 of these (a, b, c, etc) and I need to check them for different combinations, example:
if a && b && g && h && m && x && z == 1:
and then another one like:
if c && h && t && o && p && q == 1: … etc

Thanks in advance!

Why can’t you group them in arrays?

if values_match([a, b, c, d], 1):
  pass

func values_match(values, expected_value):
  return values.all(func(value): return value == expected_value)

I was asking so I could save some time coding because there are a lot of combinations to be done and I need specific combinations, because it’s about puzzles.
I think I’ll settle for if a == 1 && b == 1 && c == 1 && d == 1 :weary:

if it just checking 1 and 0 you can just use:
if a&&b&&c&&d:
it close to this:

3 Likes

I don’t know if I am getting this right but you need things to match? I have a scratch project with this way of matching a password input by a player.

func pw_text_submitted(_new_text):
	## makes player enter their username and then use the password they set.
	if pw1.text && pw2.text == pw1.text:
		MyGlobals.player_pw = pw2.text
		MyGlobals.player_name = username.text
		SaveGameGlobals.save_game()
		get_tree().change_scene_to_file("res://Desktop/boot_user_input.tscn")
		print("YAAAA, it's a macth")
	else:
		pw_wrong.visible = true
		print("BOO, make sure it matches")

Have a look at using btiwise instead. I am sure there are plenty of examples out there for GD Script.