Why the score doesn't add up from different copied node.

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

I have a main node, in the node there is an enemy (instanced scene). I copied the node to make a few enemies. I set in the enemy script that when no_health, global_script.score += 10. However, it only prints 10 every time an enemy died instead of adding all the 10’s for an accumulated score. I think this has something to do with copied node, but not sure what the problem is. Could anyone point out what the problem is? Thank you.

Maybe you can show us some of the code?

Ertain | 2020-07-17 05:47

Sure, the code is quite simple, and it works for all my player stats. However, it does not work for copied enemies, the print is always 10 rather than 10 + 10 + …

# on enemy script
func _on_Stats_no_health():
   stats.score += 10

# on Global Singletons Stats script
export(int) var initial_score = 0
onready var score = initial_score setget set_score

func set_score(value):
   score = value
   print (score)

Idleman | 2020-07-17 06:09

Is this code in one script, or is it spread across multiple scripts?

Ertain | 2020-07-17 07:24

As the comment mention, the first func is on the enemy script, and the second part is on the global script.

I think may be it is because all the enemies are copies, so they run on the same script and each time one dies, it just runs at the initial count so the scores are not cumulated.

Idleman | 2020-07-17 10:59

Found the problem. I mixed up the global script with a local script of a similar name. Once reset the path to the global script, the numbers got added up correctly. Thank you for helping.

Idleman | 2020-07-17 11:07

you may add the answer and select it so others coming here see its already solved!

p7f | 2020-07-17 12:46

:bust_in_silhouette: Reply From: Idleman

Found the problem. I mixed up the global script with a local script of a similar name. Once reset the path to the global script, the numbers got added up correctly.