Hello here my test.
Its a minimal Godot resource for saving your time.
extends Resource
class_name ScoreCount
# I added 'export' keyword because in my real project the resource has to be saved on disk
# and for some reason I needed to do that
export var score = 100
In other Script I instance the resource then mutate, then I try to reset the variable like if the player wants a new match.
extends Node
func _ready():
var test = ScoreCount.new()
print("initial ", test.score)
# Mutate the resource
test.score -= 10
print("changed score ", test.score)
# Try to reset the resource
test = ScoreCount.new()
print("reseted score ", test.score)
In this case that works.
initial 100
changed score 90
reseted score 100
But imagine I want an array of score, like in a championship.
extends Resource
class_name ScoreCount
enum{
PLAYERA,
PLAYERB
}
export var score = [100, 100]
extends Node
func _ready():
var test = ScoreCount.new()
print("initial ", test.score)
# Mutate the resource
test.score[test.PLAYERA] -= 10
print("changed score ", test.score)
# Try to reset the resource
test = ScoreCount.new()
print("reseted score ", test.score)
The result.
initial [100, 100]
changed score [90, 100]
reseted score [90, 100]
The code 'test = ScoreCount.new()' just brought me the mutated resource again !
In my real project the number of player should be higher and the score isn't their only variable. So I try to avoid to write a bunch of scalar variables, please do you know a solution ?