So what you’re trying to do is access the ammo property of a String. It’s the same as coding "Cool".ammo. Seems silly when you look at it from the computer’s perspective. But we’ve all been there.
What you are going to want to do is every time that ammo variable gets changed, emit a custom signal that you create, then have your Control node connect()ed to that signal so it can receive the change and update the UI.
Here are the Godot docs on signals. I highly recommend reading through the entire thing, they’re essential for game programming.
Would this also retrieve the ammo variable from the player? Or would I have to set up code in the control node that makes its own ammo count that decreases each time ammo_changed is emitted?
darkdestiny1010 | 2021-05-12 15:04
Nevermind, got it working! Thank you so much!
darkdestiny1010 | 2021-05-12 15:41
You could just use a single variable in the player class to manage your ammo variable:
ammo -= 1
to connect the two:
onready var player = get_node("Player") # wherever these are located
onready var control_node = get_node("ControlNode") # whereever these are located
player.connect("ammo_changed", control_node, "_on_ammo_changed")
# gets called whenever ammo_changed is emitted because of the connect() function
labelAmmo = str(ammo)
# or something like:
label.text = str(ammo)