0 votes

The game my team and i are making should have checkpoints so then you don't have to start from the first battle when pressing "restart battle" button.
How can i save current level's value and just use it if that button it's pressed?
LoseScreen.gd:

extends MarginContainer

var BattleScene = load("res://Battle/Battle.tscn")

func _on_Button_mouse_entered():
    MusicPlayer.play_sfx("button_hover")

func _on_Buttons_pressed():
    Helpers.set_initial_game_state()
    MusicPlayer.play_sfx("button_press")
    get_tree().call_group("Main", "set_scene", BattleScene)

func _on_RestartBattleButton_pressed():
    # Use current level's value to restart the game in the battle you was.
    pass

BattleStateEnemyTurn:

if fsm.state_curr == fsm.states.EnemyTurn and anim_name == "exit_enemy_attack":
        if State.get_value("player_health") <= 0:
            fsm.state_next = fsm.states.PlayerLost
            MusicPlayer.play_music("lost")
        else:
            fsm.state_next = fsm.states.PlayerTurn

Helpers.gd:

extends Node

var current_letter_bank = []
var dictionary = []

func set_initial_game_state():
    State.set_value("player_health", get_starting_player_health())
    State.set_value("current_level", 1)

    State.set_value("enemy_type", Enums.EnemyType.SLIME)
    State.set_value("enemy_health", get_starting_enemy_health(Enums.EnemyType.SLIME))

func _ready():
    initialize_dictionary()

func advance_to_next_level():
    var current_level = State.get_value("current_level")
    var next_level = current_level + 1 # How can i save this change (i.e current level = 3 if you losed in that level) ?
    State.set_value("current_level", next_level)

Edit: Nevermind, solved it.

in Engine by (117 points)
edited by

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.

Categories