The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates.

godotengine.org | Twitter

0 votes

This Error is coming when I am using MainLoop.NOTIFICATIONWMQUIT_REQUEST.

Image

My Code-

extends Node

var save_filename = "user://save_game.save"

func _ready():
    load_game()

func save_game():
    var save_file = File.new()
    save_file.open(save_filename,File.WRITE)
    var saved_nodes = get_tree().get_nodes_in_group("Saved")

    for node in saved_nodes:
        if node.filename.empty():
            break

        var node_details = node.get_save_stats()
        save_file.store_line(to_json(node_details))

    save_file.close()

  func _notification(what):
    if what == MainLoop.NOTIFICATION_WM_QUIT_REQUEST or what == MainLoop.NOTIFICATION_WM_GO_BACK_REQUEST:
        save_game()

func load_game():

    var save_file = File.new()
    if not save_file.file_exists(save_filename):
        return

    var saved_nodes = get_tree().get_nodes_in_group("Saved")

    for node in saved_nodes:
        node.queue_free()

    save_file.open(save_filename,File.READ)
    while save_file.get_position() < save_file.get_len():
        var node_data = parse_json(save_file.get_line())
        var new_obj = load(node_data.filename).instance()
        get_node(node_data.parent).call_deferred('add_child',new_obj)
        new_obj.load_save_stats(node_data)
Godot version Godot_v3.3-stable
in Engine by (20 points)

1 Answer

+1 vote
Best answer

The screenshot you posted shows there is a typo in your code :)

by (736 points)
selected by

Actually yeah and then i also restarted the godot editor

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 Frequently asked questions and 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 [email protected] with your username.