|
|
|
 |
Reply From: |
kidscancode |
This is really going to depend on how you have things set up. The person in the linked question seems to have a very specific setup using nodes for score and life, which wouldn’t apply to you if you’re using variables for them.
Regardless, it could be as simple as calling
get_tree().reload_current_scene()
to restart everything, or you may need to write a function that resets the values of the variables and you call that when you want to reset.
If you include more information about what you have so far, I could try and be more specific.
If you want to preserve the value of the variable after a restart, put the variable in your autoload script. Then it will be independent of the scene.
When you call goto_scene() the current scene is freed. So current_scene.free() will fail.
Also, a couple of tips:
-
When you add an autoload, you don’t have to use get_node("/root/global"), you can just access it by global.goto_scene() - in the Autoload tab you can set the name it will be referred by.
-
Remove all those pass lines. They do nothing but clutter up your code.
kidscancode | 2019-02-14 22:04
thanks for your answer. when i remove current_scene_free() from the global and added global.goto_scene() . When i press play the level 1 scene merges with the game_1.tscn and the game crashes.

When i removed the life_current_1 from game script and added to the label which had life value and removed the game global from area 2D ; i get the error as “life_current_1 not found”.
Can i send you my project and tell me where i am doing wrong ? please.
THE HELIX | 2019-02-15 05:36
Could u please show me how to seperate the life_current variable from the game script and should I put the life _current value to area2D or label script ?
THE HELIX | 2019-02-15 18:42
Post a link to your project and I’ll try to look at it this weekend.
kidscancode | 2019-02-15 18:55
I figured out how to separate the value of life from autoload and save the coins but i have 2 questions
1 : how to make the label show the life value decreasing to 0

here is the code for Area 2d , i need to make the label show the values of life points
Here is the path of label

Here Life_2 is the label i need
2 : How to add the amount of coins collected in a level to the current amount of coins already present in the game ?
Can you help me to solve those two problems?
THE HELIX | 2019-02-16 15:53
Can you solve the two problems which I posted above please ?
THE HELIX | 2019-02-16 18:36