Need help updating script to Godot 4

Godot Version

4.2.2 Stable

Question

I am new to Godot, so I have been using online tutorials with my scripts. I soon learned that some of the tutorials are outdated. I could use some help updating my script so that it will work for Godot 4. The script is supposed to detect when a specific slider is updated then update a specific line in a text document. Any advice is appreciated.

extends Node

func _init():
    load_settings()

func save_settings():
    var file = File.new()
    file.open("user://settings.txt", File.WRITE)
    file.store_line(str(get_node("MusicSlider").value))
    file.store_line(str(get_node("SFXSlider").value))
    file.close()

func load_settings():
    var file = File.new()
    if file.file_exists("user://settings.txt"):
        file.open("user://settings.txt", File.READ)
        get_node("MusicSlider").value = float(file.get_line())
        get_node("SFXSlider").value = float(file.get_line())
        file.close()

func _on_MusicSlider_value_changed(value):
    save_settings()

func _on_SFXSlider_value_changed(value):
    save_settings()

Here is a porting doc

1 Like

what is broken with it? are the signals connected?

It did not recognize the “File” class. I just learned earlier today that Godot 4 changed “File” to “FileAccess”.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.