Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | whooshfrosted | |
Old Version | Published before Godot 3 was released. |
Say I have a script that is created and made ready for use like so:
var script = preload("res://the_script.gd").new()
How would I duplicate this script?
I tried this but it doesn’t work:
var new_script = script.new()
Try .instance()
instead of .new()
timoschwarzer | 2017-07-20 12:33
No good.
Invalid call. Nonexistent function ‘instance’ in base 'Reference
whooshfrosted | 2017-07-20 22:30
Yes, right. Since GDScripts are resources, it is .duplicate()
here.
timoschwarzer | 2017-07-21 12:59
Same result, since once I call new on it, becomes a reference.
“Invalid call. Nonexistent function ‘duplicate’ in base 'Reference”
Duplicate would work in the code I posted below though.
whooshfrosted | 2017-07-21 15:24