Hi! I don't know how to make a score that increases

Godot Version 4.2.1/2

Question

How would you make a score that increases each time a enemy is defeated?

There’s a good tutorial on Godot Docs that teaches you basics like this.
You will find the answer you’re looking for there.

Godot Docs | Your first 3D game

2 Likes

you can create an autoload script and call it something like “ScoreHandler” or whatever you want to call it and store your score variable there, on your enemy you can have a variable like increase_score_num. Then on the block of code where you have the enemy die, just before the .queue_free(), have ScoreHandler.score += increase_score_num.

1 Like

THANK YOU, this worked

1 Like

You’re welcome! glad i could be of help

This was a good video for that. With cute bats too.

My code has an error now. It says invalid get index score (on base Label (ScoreHandler.gd)) and makes the score equal null. Do you know how you might fix that? (sorry if I’m wasting your time)

You can always modify your database variables directly.

When the enemy dies just call a function to change the data.

Example :

class_name Database

static var DeathCount : int
class_name Enemy

func EnemyDeath():
	Database.DeathCount += 1

I created two global variables in my game so that any part of the code can read and adjust them easily. Like this:

extends RichTextLabel

func _process(delta):
	text = ("Score " + str(global.score))

Sorry, didnt see this till now. Im curious as to if you were able to solve it

1 Like

I was thank you

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.