Topic was automatically imported from the old Question2Answer platform.
Asked By
oliverruehl
Old Version
Published before Godot 3 was released.
Hello all,
I’m really in love with this engine now, but my programming skills (I programmed Python ages ago) are not up to speed yet.
I’d really appreciate your help.
I have created a global.gd file which is autoloaded
It contains a variable for the score = 0
When my character hits an enemy the score is increased by +1
… all works fine (I check all that stuff with print).
But how do I update the element on screen while the game is running?
I’m thinking of something like a “polling” mechanism… but I guess its even easier
Thanks guys
I’ll be posting more about my game soon!
One of them maybe is to create a callback on that element you want to update (a Label for example) and connect it to a signal that is emitted when the score is increased (user signal). Then the callback should receive the new score or directly access to global.gd and to the updated score.
edit 2: sigh. had to change it again because unfortunately setScore won’t be triggered when global.gd changes it Realised this because I’m scratching my head working on my own app that had this problem.
You could use setget in combination with a custom signal. At least this will trap everywhere that score is changed, so you only need to emit your signal once.
#global.gd
var score = 0 setget setScore
signal score_changed
# called when something **external** changes score
func setScore():
emit_signal("score_changed", score)