Command System with function reference!

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By xDGameStudios

I’m trying to implement a modular command system for my game (tactical RPG) and the ideia behind the method was to create Resources (Commands) that would have a besides the name and other stuff, a reference to a method!! Reference to methods cannot be exported so I came up with this solution.

this would make it so the resource now has a drop down enum containing all the methods existing inside the ActionsCode.gd file. This file would have this structure:

this would allow me to store all the command methods inside a file and then reference them the commands would receive as arguments whatever I intended. And I could call them as:

ActionsCode.new().call(method_name)

Another alternative I though of would be storing all the commands inside a folder… use the directory class to go through them, create the enum just like in the first image… but now each Command would be stored inside a different file and could be called using:

load(my_command_path).new().execute(arguments);

“execute” would be a common entry point for each command.
What do you think, what would be the cons and pros of these approaches… the ideia is to separate code from design when working in projects with programming team and design team.