0 votes

In the project there are several numbers which contain the script Button.gd

extends KinematicBody2D 

var the_number = randi()%22+-3

func _on_Hex_pressed():
    $Sprite.modulate = Color(1.0, 1.0, 1.0, 1.0)
    Add.numbers_to_add.append(the_number)
    Add.button_the_number_came_from.append(self)

They contain an autoload script Add.gd

extends Node

var numbers_to_add : Array = Array()
var button_the_number_came_from : Array = Array()


func _process(delta):
    if numbers_to_add.size() > 2:
        if numbers_to_add[0] + numbers_to_add[1]  == numbers_to_add[2]:
            for index in button_the_number_came_from.size():
                button_the_number_came_from[index].queue_free()
        elif numbers_to_add[0] + numbers_to_add[1]  != numbers_to_add[2]:
            print("no") 
        button_the_number_came_from.clear()
        numbers_to_add.clear()
    print(numbers_to_add)

When the sum of two numbers are not equal to the result no is printed in the output.How can I access this Add.gd program line below in the func _on_Hex_pressed(): of the Button.gdscript so I can change the sprite color when no is printed ?

  elif numbers_to_add[0] + numbers_to_add[1]  != numbers_to_add[2]:
in Engine by (141 points)

1 Answer

0 votes
Best answer

Are you trying to read the output console? Don't know if it's possible. But you could emit a signal for this situation.

An example:

Add.gd 
    signal printed_no
func _process(delta):
elif numbers_to_add[0] + numbers_to_add[1]  != numbers_to_add[2]:
    print("no")
    emit_signal("printed_no")


Button.gd
func _ready():
    Add.connect("printed_no", self, "_on_printed_no")
    pass
func _on_printed_no():
    #do stuff
    pass
by (190 points)
selected by

Thank You; It worked .

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.