Trying to change script string content and take effect immediately

Godot Version 4.2


i have a autoload node’s script like this

func generateConstantFile():

    var script_content:String = ""
    var file:FileAccess ="res://scene/BattleScene/BattleCharacterPreset/Script/",FileAccess.WRITE_READ)
    var directories:Array = FileUtils.get_files_path_in_directory(rootDirectoryBattlerInitInfo)
    script_content += "enum BattlerName{\n"
    for directory:String in directories:
        script_content += "\t" + directory.get_basename().split('/')[-1] + ",\n"
    script_content += "}\n"

    print("generate complete")

as above,i create this script to automatically change script that already exists,and i finally aims to let other script can load the latest content within this changed script contains enum is example:

func autoGenerateCharacterNode():
    var BattlerName = ResourceLoader.load("res://scene/BattleScene/BattleCharacterPreset/Script/").BattlerName
    for battlerName in BattlerName:
        # print(battlerName)
        var battleCharacterNode:BattleCharacterNode = BattleCharacterNodeTSCN.instantiate()

        battleCharacterNode.owner = battleCharacterNode
        var pack:PackedScene =

        var err =,defaultPackedSceneStoragePath + battlerName + ".tscn")
        if err != OK:
            print("Failed to save specialized scene file!")


it seems like this script can only get content whose version is before game launch,but not the version that changed after game launch.Could anyone give another way to help achieve my purpose?
In conclusion,i have created several scripts can update other scripts automatically so as to let my node load the latest content after game launched.(want to avoid using Dictionary,because enum variable can aplly automatic completion