Add extra life after 100 points

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

Im trying to add an extra life after player collects 100 points. I want it to happen every 100 points.

My code:

func getting_a_life_from_points():
if Global.Score_count % 100 == 0 and Global.Score_count != 0:
	PlayerStats.change_lives(+1)

The code works but the problem is that when i call the function in physics process it instantly adds more than 1 life. When i call the function in _ready() it only works after reloading the scene.

:bust_in_silhouette: Reply From: Wakatta

This my friend are why signals are a thing.

Or call your function whenever you increase the points.

Thanks, signals worked great :slight_smile:

Maciu01 | 2022-10-31 17:29

:bust_in_silhouette: Reply From: godot_dev_

Like Wakatta stated, signals can be useful for this. You could have your Global script have a setter and getter function to change the points. Inside your point setter, emit a signal (e.g., “points_changed”) everytime the points variable changes. Then connect your getting_a_life_from_points function to that signal, and check the point count.