system
June 14, 2020, 7:42am
1
Attention
Topic was automatically imported from the old Question2Answer platform.
Asked By
Pneuma
Im trying to subtract 100 points from the total score, then once that is done each click on the button will be + 10 instead of + 1. For the life of me I can’t figure it out. Here is my code:
extends Control
onready var REK = $Label
var score = 0
var number1 = null
func _ready():
updateUI()
func updateUI():
$Label.text = str(score)
func _on_Button_pressed():
score = score + 1
updateUI()
func _on_Buy_pressed():
if score >= 100:
score = score - 100
updateUI()
if _on_Button_pressed():
score = score + 10
updateUI()
else:
updateUI()
system
June 14, 2020, 10:31am
2
Reply From:
Lisandro Lorea
You can have some variable like:
var inc_amount = 1
and onButton_pressed will do score = score + inc_amount
Then onBuypressed() should set inc_amount to 10 and that’s it
yes, here is an example with a dictionary:
extends Control
var target_increment = {100:10, 500:15, 1500:20, 5000:30}
var current_target= 0
var bonus = 1
var score = 0
func _ready():
updateUI()
func updateUI():
$Label.text = str(score)
func onButton_pressed():
score = score + bonus
updateUI()
func onBuypressed():
if current_target < target_increment.size():
if score >= target_increment.keys()[current_target]:
score = score - target_increment.keys()[current_target]
bonus = target_increment.values()[current_target]
current_target = current_target + 1
updateUI()
estebanmolca | 2020-06-14 11:03