0 votes

how to set a button woth diamonds or coins to continue the game if the player dies and wants to continue the game with same score using that button

in Engine by (14 points)
recategorized by

1 Answer

0 votes

Do something like this:

Node hirarchy:

Game(Node2D)
    Currency(Node2D)
        Message(Label)
    Continue(TouchscreenButton)

Code in Currency:

extends Node2D

var val = 150

func _restrict(amount):
    var outcome
    if val < 0:
        val += amount
        $Label.set_text("You don't have enough money.")
        outcome = false
    else:
        outcome = true
    return outcome

func _substract(amount):
    val -= amount
    var outcome = _restrict(amount)

func _add(amount):
    val += amount

Code in Continue:

extends TouchScreenButton

onready var amount_to_continue = 50

func _ready():
    pass

func _on_Continue_released():
    var currency = get_node("../Currency")
    var outcome = currency._substract(amount_to_continue)
    if outcome:
        _continue_with_game()

Then adjust and complement that kind of logic for your game.

by (840 points)
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 Frequently asked questions and 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 [email protected] with your username.