im making a game where im in a main_room area and collect some objects and go back - forth to other areas . But when i do change_scene_to_file , my data(the objects that i collected) refreshes back. i want my data to be saved. And i want to do it in a main_room.show - hide way. is it possible? i created a scene managar script as autload and stuck right there :D. can someone help. i’ll be submitting my game couple hours later
i crated a base GameScene as node and wrote the code
and my other room scenes are Node2D but how should i write the change_scene function on autload
Main room has 4 doors which will lead up to 4 room scenes . I currently have 1 ready which is red_room . when i click on the red-room colliison shape i want red_room scene to show up and when i click to go-back button i want to go back to main_room
There are several ways you can do this. You could, for example, have all of the scenes remain in the tree and just .show() and .hide() them to make them visible or not. There’s an is_visible_in_tree() you can call in script to see if a node is visible; as long as they’re in the tree, they’ll still call _process() &c. even if they aren’t visible.
If you want to swap things in and out (say, your scenes are big enough that you’re worried about memory, or you don’t want to deal with gating updates based on visibility) you could move all of the vars you want to be persistent into a global script. You can make these under the project menu, and if you make one and name it (say) GameState, and do something like:
[...stuff...]
enum Emotion: { bored, confused, miffed, ambiguous }
var Inventory: Array = []
var HitPoints: int
var BananaCount: float
var MentalState: Emotion = Emotion.ambiguous
func set_mental_state(e: Emotion) -> void:
if e == MentalState:
return
print("Changing emotional state!")
MentalState = e
[...stuff...]
Other scripts can call into this:
# some other script...
func damage_player():
GameState.set_mental_state(GameState.Emotion.miffed)
GameState.HitPoints -= 1
if GameState.HitPoints < 0:
GameState.BananaCount *= 0.5