Godot Version
4.1
Question
hi, im having an issue with the score system in my game
the problem is that when i first play the level, when i collect something that has another type of points, the type of points replace the other type of points (like when i collect something that has a different type of points, it replaces with 1000 instead of adding up with the other type of points)
however, in the 2nd time (when the player dies), the same type of points and another one add up but when i collect something that has another type, it replaces the other types (for example: if its 500, the other points type replaces it with 200 when i collect something that follows that type of points)
so is there a way to solve this? here are the scripts incase your interested
the 1st (and 2nd) type of points:
extends Node
class_name PelletsManager
var total_pellets_count
var pellets_eaten = 0
@onready var chomp_1_player = $"../soundPlayers/chomp1_player"
@onready var chomp_2_player = $"../soundPlayers/chomp2_player"
@onready var points_manager = $"../pointsManager"
@onready var ui = $"../UI" as UI
const BASE_POINTS_FOR_PELLET_VALUE = 10
const BASE_POINTS_FOR_POWERPELLET_VALUE = 50
var pellet_points = BASE_POINTS_FOR_PELLET_VALUE
var powerpellet_points = BASE_POINTS_FOR_POWERPELLET_VALUE
var points = 0
@onready var powerpellet_player = $"../soundPlayers/powerpellet_player"
@export var ghost_array: Array[Ghost]
var eaten_ghost_counter = 0
func _ready():
var pellets = self.get_children() as Array[Pellet]
total_pellets_count = pellets.size()
for pellet in pellets:
pellet.pellet_eaten.connect(on_pellet_eaten)
for ghost in ghost_array:
ghost.run_away_timeout.connect(on_ghost_run_away_timeout)
func on_pellet_eaten(should_allow_eating_ghosts: bool):
print("wakawaka")
points += pellet_points
if !chomp_1_player.playing:
chomp_1_player.play()
else:
chomp_2_player.play()
ui.set_score(points)
if should_allow_eating_ghosts:
powerpellet_player.play()
points += powerpellet_points
ui.set_score(points)
for ghost in ghost_array:
if ghost.current_state != ghost.GhostState.STARTING_AT_HOME:
ghost.run_away_from_pacman()
if pellets_eaten == total_pellets_count:
get_tree().change_scene_to_file("res://SCENES/gameover.tscn")
# The 2nd type of points
func on_ghost_run_away_timeout():
eaten_ghost_counter += 1
if eaten_ghost_counter == ghost_array.size():
points_manager.reset_points_for_ghosts()
eaten_ghost_counter = 0
powerpellet_player.stop()
the 3rd type of points:
extends Node
class_name PointsManager
@onready var ui = $"../UI" as UI
const BASE_POINTS_FOR_GHOST_VALUE = 200
const BASE_POINTS_FOR_PELLET_VALUE = 10
const BASE_POINTS_FOR_POWERPELLET_VALUE = 50
var ghost_points = BASE_POINTS_FOR_GHOST_VALUE
var pellet_points = BASE_POINTS_FOR_PELLET_VALUE
var powerpellet_points = BASE_POINTS_FOR_POWERPELLET_VALUE
var points = 0
func pause_ghost():
points += ghost_points
get_tree().paused = true
await get_tree().create_timer(1.13).timeout
get_tree().paused = false
ghost_points += BASE_POINTS_FOR_GHOST_VALUE
ui.set_score(points)
func reset_points_for_ghosts():
ghost_points = BASE_POINTS_FOR_GHOST_VALUE