This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
0 votes

Hi!

I created a Score-Singleton which updates score-labels using signals when 4 different texture-buttons are pressed. When running the scene, this is exactly what the Score-labels (BeziehungScore, KontrolleScore and UnterrichtScore) are doing (in the background), but the updated values won't show up in the Score-label instance. In the end, this is not a problem at all, since I only want to show the final score (= current values of the Score-labels) in an end-screen (like a high score screen). But I'm really curious why the labels are not visible when running the scene. Any ideas?

Main Scene:

extends Control

const score = preload("res://Score.tscn")

onready var handwritingsound = $HandwritingSound
onready var main
option1 = $MainOption1
onready var mainoption2 = $MainOption2
onready var main
option3 = $MainOption3
onready var main_option4 = $MainOption4

var Beziehungscore = 0
var Kontrolle
score = 0
var Unterricht_score = 0

func ready():
var show
score = score.instance()
self.addchild(showscore)

Score.connect("update_BeziehungScore", self, "_update_Beziehung_score")
Score.connect("update_KontrolleScore", self, "_update_Kontrolle_score")
Score.connect("update_UnterrichtScore", self, "_update_Unterricht_score")

func onHandwritingSoundfinished():
handwriting
sound.stop()

func onSchoolBellSoundfinished():
main
option1.show()
mainoption2.grabfocus()
mainoption2.show()
main
option3.show()
main_option4.show()

func onMainOption1pressed():
Score.emit
signal("updateUnterrichtScore", 10) # +10 UnterrichtScore (Pünktlichkeit)
print(Unterricht
score)

func onMainOption2pressed():
Score.emit
signal("updateKontrolleScore", -10) # -10 KontrolleScore
print(Kontrolle
score)

func onMainOption3pressed():
Score.emit
signal("updateBeziehungScore", 10) # +10 BeziehungScore, - 10 Unterricht
Score.emit
signal("update_UnterrichtScore", -10)

func onMainOption4pressed():
Score.emit
signal("updateKontrolleScore", 10) # +10 KontrolleScore , -10 Unterricht
Score.emit
signal("update_UnterrichtScore", -10)

func updateBeziehungscore(Beziehungpoints):
Beziehungscore += Beziehungpoints
Score.Beziehungscore.text = str(Beziehungscore)

func updateKontrollescore(Kontrollepoints):
Kontrollescore += Kontrollepoints
Score.Kontrollescore.text = str(Kontrollescore)

func updateUnterrichtscore(Unterrichtpoints):
Unterrichtscore += Unterrichtpoints
Score.Unterrichtscore.text = str(Unterrichtscore)

Score-Singleton:

extends Control

onready var Beziehungscore = $Beziehung/BeziehungScore
onready var Kontrolle
score = $Kontrolle/KontrolleScore
onready var Unterricht_score = $Unterricht/UnterrichtScore

signal updateBeziehungScore(Beziehungpoints)
signal updateKontrolleScore(Kontrollepoints)
signal updateUnterrichtScore(Unterrichtpoints)

in Engine by (17 points)

The buttons are TextureButtons btw. I've tested "normal" buttons in another project with a similar code, and there, the values are updating on screen.

I get the following errors for the lines:

Score.connect("updateBeziehungScore", self, "updateBeziehungscore")
Score.connect("updateKontrolleScore", self, "updateKontrollescore")
Score.connect("updateUnterrichtScore", self, "updateUnterrichtscore")

W 0:00:00.540 The function 'connect()' returns a value, but this value is never used.
<C++-Fehler> RETURNVALUEDISCARDED
Main.gd:19

Is there something I miss with the signals?

Ok. I've found out that my background-image (a TextureRect-node) is blocking the autoload-singleton from showing in the scene. Isn't that strange?
Is there a workaround, or how can I prevent this from happening? :)

And now I've found the solution. I created a Canvas Layer, put the TextureRect as a child of Canvas Layer, and changed the Layer-index to -2.
Solved! :)

Please log in or register to answer this question.

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.