I have set up an A script to automatically load. A has attributes b and c. After a period of time, the values of b and c have changed. I would like to reset the A script to restore attributes b and c to their original positions, without implementing the code below. Is there any other way?

func reload():
b = 0
c = 0

I hope it's the kind of script that removes automatic loading, then creates the same script and sets it to automatic loading. Or create a new script to replace the original one. Do you have any good methods

  • kuligs2 replied to this.
  • JiuMengD Reassign the script. It will invoke script's constructor _init() again.

    var s = get_script()
    set_script(null)
    set_script(s)

    kuligs2
    The problem is how to restore the default value of global variables. Compared to a node, I can definitely queue_free() that node, and then use packedscene to generate a new node, which will restore the default value. This is very simple, I know. But what I encountered was how to restore the default value of an automatically loaded script. I tried the above method, but now I can no longer find it, it becomes NULL. Example:

    A is an automatic loading script
    I will add A queueun_free()
    Then, the. gd file new()
    Insert the root node,
    He indicated that node A has been released, which proves that the new one I have added cannot replace the original one.

    So can I only set properties to default values one by one
    Is there anything else I can do

      JiuMengD Reassign the script. It will invoke script's constructor _init() again.

      var s = get_script()
      set_script(null)
      set_script(s)

        JiuMengD did you even check the link i posted? there is a solution there. you write function where you take all current property values and store them in a dictionary and then you create reset function to run when you need it and the first function to run on ready.

          kuligs2 Perhaps my description is incorrect. What I am looking for is other convenient operations besides assigning attributes myself. However, I have found a way. Thank you for your answer

          xyz
          s = root.get_node("/Events").get_script().duplicate()
          #Some changes...
          root.get_node("/Events").set_script(s)

          I solved the problem in this way
          Thank you for your answer