0 votes

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 onButton_pressed():
score = score + 1
updateUI()

func onBuypressed():
if score >= 100:
score = score - 100
updateUI()
if _on
Button_pressed():
score = score + 10
updateUI()
else:
updateUI()

in Engine by (32 points)

1 Answer

0 votes
Best answer

You can have some variable like:
var inc_amount = 1

and onButtonpressed will do score = score + incamount

Then onBuypressed() should set inc_amount to 10 and that's it

by (118 points)
selected by

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()
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.