how to put a variable on the screen?

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

How can I create a text, and in that text count a variable number that I have (in a 2d game?

:bust_in_silhouette: Reply From: jgodfrey

Here’s a working sample. You’ll need to modify it as appropriate to fit your needs.

First, create a new, simple scene containing the following:


Next, attach the following script to the Node2D

extends Node2D

var counter = 0

func _process(delta):
	counter += 1
	$Label.text = "Counter: %s" % counter

In each frame, that’ll increment the value of the counter variable and then put it in the Label, formatted as Counter: #.