Help with if statement(s)

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By elek95eel
:warning: Old Version Published before Godot 3 was released.

Basically, I have my logic almost set up so that a different texture is used when certain requirements are made.

As you can see, certain textures are loaded first and then iterate through row, column and region groups based on the cell’s position to check for what’s there. I want to figure out how to ONLY use var wrong when var normalis detected and when var entered is detected for anything besides its current position.

Pressing 1 - function

func _on_1_pressed():
var normal = preload("res://images/normal_tiles/1.svg.png")
var entered = preload("res://images/entered_tiles/1blue.svg.png")
var blank = preload("res://images/normal_tiles/blank.svg.png")
var wrong = preload("res://images/wrong_tiles/1h_red.png")
var tile_pos = get_cell_position()
set_normal_texture(normal)
var allgroups = rcr()
for group in allgroups:
	var nodegroup = get_tree().get_nodes_in_group(str(group))
	for node in nodegroup:
		if (node.get_normal_texture() == normal) or (node.get_normal_texture() == entered and p_dia.get_pos() - Vector2(25,75) != get_cell_position()):
			print("'invalid")
			set_normal_texture(wrong)

Would this sample help you : GDScript reference — Godot Engine (stable) documentation in English ?

Omicron | 2017-06-15 08:30

by what you said( i will use normal and entered as bools ) what you need is:

 var normal = // checking if normal is detected
 var entered = // checking if entered is detected
 if normal and entered:
      Do something here

you can just place what normal and entered equals instead of using more variables

rustyStriker | 2017-06-15 13:08

This seems to work thus far but using else just negates the if statement completely.

var valid = preload("res://images/normal_tiles/blank.svg.png")
var wrong = preload("res://images/wrong_tiles/1h_red.png")
var allgroups = rcr()
for group in allgroups:
	var nodegroup = get_tree().get_nodes_in_group(str(group))
	for node in nodegroup:
		var normal = node.get_normal_texture() == preload("res://images/normal_tiles/1.svg.png")
		var entered = node.get_normal_texture() == preload("res://images/entered_tiles/1blue.svg.png")
		if (normal) or (entered):
			print("Nah")
			set_normal_texture(wrong)

EDIT _- I think I know why I can’t set the texture button after the if statement. Somehow, I need to use get_node based on its rect/pos property so I can set a different property as they are all instanced buttons.

elek95eel | 2017-06-15 13:44