Topic was automatically imported from the old Question2Answer platform.
Asked By
idleTim
Godot 4: I’m tying to use a spinbox to “hire/fire” laborers and remove/return to “available labor” pool (label), but can’t figure out how…
How do i reference spinbox values to be applied to other functions or variables?
desired operation:
spinbox(value) +1 = available labor (label) -1
spinbox(value) -1 = available labor (label) +1
spinbox and label are on the same panel
label is not child of spinbox or button
Spinbox has a value member you can check manually, or you can connect to its value_changed(value) signal to only respond to updates.
Label data can be accessed in its text member which is a string, if you want to write a numeric value, you’ll have to convert to string first.
I’m not sure what those equations supposed to mean, but here goes:
func _on_SpinBox_value_changed(value: float) -> void:
var multiplier: int = -1 if value > last_value else 1
var label_value: int = $Label.text.to_int()
$Label.text = String.num_int64(label_value + 1 * multiplier)
last_value = value
thanks!
i’ll try that tonight after work, and post my results…
idleTim | 2023-03-22 10:31
that got it working, thank you!
renamed the values and labels so my multiple spinboxes won’t overlap…