How to access a autoload script in godot .

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By THE HELIX

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]:
:bust_in_silhouette: Reply From: null_digital

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

Thank You; It worked .

THE HELIX | 2019-12-06 03:59