Godot Version
v4.7.2.stable.official [ed1daf0bf]
Question
Hello! I'm currently making a 2D platformer for fun (total beginner) and I recently added script for my coins and score UI. I was able to get it to work nicely for one coin, but I planned on having 2 coin types in my level (one worth 1 point [greencoin], one worth 10 points [passionflower]). I can't seem to figure out how to re-write or edit the update function in the score UI script to include and connect to both integer variables. Any help is greatly appreciate, thanks!
Current Level Script:
class_name Level1 extends Node2D
signal greencoin_updated(int)
signal passionflower_updated(int)
@onready var collectables: TileMapLayer = $Collectables
var greencoin: int = 0
var passionflower: int = 0
func _ready() → void:
call_deferred(“connect_signals”)
func connect_signals() → void:
for child in collectables.get_children():
if child is GreenCoin:
child.is_collected.connect(greencoin_collected)
if child is PassionFlower:
child.is_collected.connect(passionflower_collected)
func greencoin_collected() → void:
greencoin += 1
greencoin_updated.emit(greencoin)
func passionflower_collected() → void:
passionflower += 10
passionflower_updated.emit(passionflower)
Current Score UI Script:
class_name ScoringUI extends TextureRect
@onready var label: Label = $Label
func update(greencoin: int) → void:
label.text = str(greencoin)