how to set a button woth diamonds or coins to continue the game

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By mustansir

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

:bust_in_silhouette: Reply From: Footurist

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.