0 votes

Instead of not letting the icon change, if this icon already exists, it simply passes.
What has been done wrong?
Here is the code:

select = "0"
apply1 = "0"
apply2 = "0"
apply3 = "0"
func _on_orange_pressed():
    select = "orange"
func _on_apple_pressed():
    select = "apple"
func _on_pear_pressed():
    select = "pear"
func _on_apply1_pressed():
    if apply2 or apply3 == select:
        if select == "orange":
            $icons/icon1.texture = game.orange
            apply1 = "orange"
        elif select == "apple":
            $icons/icon1.texture = game.apple
            apply1 = "apple"
        elif select == "pear":
            $icons/icon1.texture = game.pear
            apply1 = "pear"
func _on_apply2_pressed():
    if apply1 or apply3 == select:
        if select == "orange":
            $icons/icon2.texture = game.orange
            apply2 = "orange"
        elif select == "apple":
            $icons/icon2.texture = game.apple
            apply2 = "apple"
        elif select == "pear":
            $icons/icon2.texture = game.pear
            apply2 = "pear"
func _on_apply3_pressed():
    if apply1 or apply2 == select:
        if select == "orange":
            $icons/icon3.texture = game.orange
            apply3 = "orange"
        elif select == "apple":
            $icons/icon3.texture = game.apple
            apply3 = "apple"
        elif select == "pear":
            $icons/icon3.texture = game.pear
            apply3 = "pear"
in Engine by (43 points)

1 Answer

+1 vote
Best answer
 if Object1 or Object2 == Object3


 if Object1 == Object3 or Object2 == Object3

objects in an if statement in the end should evaluate to a boolean, usually if the item is null it is false and true if otherwise, what you did is basically saying

 if (Object1 != null) or (Object2 == Object3)

while object1 is not null, you wont be able to do anything

**just a side note use return instead of pass, as pass is just a placeholder and wont block anything(if im not mistaken) while return works like in any other language and exit the code block and goes back to the previous one

by (1,204 points)
selected by
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.