Godot Version 4.2.1/2
Question
How would you make a score that increases each time a enemy is defeated?
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.
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.
THANK YOU, this worked
You’re welcome! glad i could be of help
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
I was thank you
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.