Welcome to the forums @SangucheMan!
By global script, do you mean an autoload script? If so, you may want to (re)set bricks
to the number of bricks in the level after loading. Additionally, you should not need to queue_free
the current scene if you call change_scene
, as change_scene
should handle it for you automatically.
func brick_dead():
bricks -= 1
if (bricks <= 0):
# reset the brick count
bricks = goalBricks
get_tree().change_scene(second_level_here)
To have different brick counts, what you can do is add something like this in _ready
to the brick script:
func _ready():
# assuming "global" is the name of the global/autoload script
global.add_brick()
Then you can adjust the global script a bit to add the new function and functionality:
var level_changed = false
func brick_dead():
bricks -= 1
if (bricks <= 0):
# only change levels if we have not just changed level.
# This prevents an instant level change on a new scene load
if (level_changed == false):
level_changed = true
get_tree().change_scene(second_level_here)
func add_brick():
bricks += 1
if (level_changed == true):
level_changed = false
# now we will change levels if the brick count is less
# than zero.
With the ball instances, how are you instancing/spawning them? They should be deleted as part of the scene change if they are children of the main scene.