This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
0 votes

Hi everyone! I desperately need your help. I have three scenes: a player, a coin, and a Main, which contains both. My problem is to add a label that scores the points when the player collects the coin. I tried in every way, looking also in this section, but there is nothing to do! I just can’t start the score! Anybody could help me, please? :-(

in Engine by (96 points)

could you share us the code?

What code? Currently, the only code I've added is the one of the answer below.

2 Answers

+1 vote
Best answer

onready var score = $"../CanvasLayer/Score"

func _on_body_entered(body): 
    if body == player:

var score = 0

func add_score(val):
    score += 1
    text = score
by (202 points)
selected by

Thank you! ;-)

+1 vote

Assuming you have a scene looking something like this?
- Main
-- Label
-- Player
-- Coin
--- Area2D
you could do a score like so

var score = 0 #hold the score
func addScore(val): # function to add the score
    score += val # add val to score
    $Label.set_text(score) # Set the text of label to score

func _on_Area2D_area_entered(): # when something enters area2D
    addScore(1) # add 1 to score
by (201 points)

It doesn’t work! :_(

My scene is something like this:

  • Main

-- Player

-- Coin (Area2D)

-- CanvasLayer

--- Score

I tried to insert the function in the Score script, and addScore () first in the coin script, then in the Main script, but nothing happens. In which scripts should I enter the code?

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.