#Dynamically load functions to scene

1 messages · Page 1 of 1 (latest)

limber patio
#

I'm looking for a way to load NON-static functions to a scene of a custom type Chapter. My current design had the root node of the scene load a script file:

events = load(AllEvents.events[event_list_id]) # event_list_id is an export var```

The script file as of now contains static functions for the node to use. This is where I noticed there was an issue:

```static func pre_fade_event(c: Chapter):
  c.loadBulkUnits([
    Globals.unit_loader.new(0, 0, 0, 20, Vector2(15,10), Vector2(15,10), [1, 0, 2], [0]),
    Globals.unit_loader.new(1, 1, 0, 1, Vector2(8,0), Vector2(13,8), [0, 2], [0]),
    Globals.unit_loader.new(1, 1, 1, 1, Vector2(16,5), Vector2(14,6), [1], [0]),
    ], true)
  await c.bulk_load_complete
  await c.no_more_move```
Because these functions are static, I'm unable to utilize await properly. The function is being called by the root scene like so:

```new_node_rec = load(Globals.CHAPTER_SCENES[chapter_id]) # Chapter is loaded
to_root = new_node_rec.instantiate() # Chapter is instantiated
add_child(to_root) # Chapter added to root node tree
to_root.events.pre_fade_event(to_root) # Chapter pre-fade event execute
# Using await on the line above softlocks the game

# DO NOT FADE UNTIL PREVIOUS EVENT IS FINISHED
fade_effect.transition(5) 
await fade_effect.done_fading```
As of now, the fade effect after the execution will run before the pre-fade function finished. How should I structure this to prevent that from happening?

Thanks
scarlet plume
#

Does making the static function not static not work? Also, would @static_unload hel?

limber patio