Skip to content

Tutorial Variable Creator

Kamran Wali edited this page Dec 1, 2024 · 7 revisions

Tutorial Variable Creator

I have also added a feature that allows to share/use data in a performant way by extending the Resource script. For now there are 3 categories of data share and each have their own different data types.

Fixed Vars

In this category different type of data types are shared, example bool, float, int, string etc. You only need to create one fixed var and share it with multiple objects, example - If five objects needs an int value of 1 then create a fixed var of type int that has the value 1 and share that. In that way only one int value of 1 is created instead of five which saves some memory. Like the name suggests the values are fixed and can/should NOT be updated. Otherwise it defeats the purpose of its function. Only call the get_value() function to get the value and do NOT change the property _value through script.

Managers

This category shares different type of managers instead of data types. Managers are scripts that have a bit of complex logic to it and these manager resources helps to share the references to those managers in a decoupled way. In this case unfortunately Variable Creator will only create managers that are created in CodeOptPro but if you want to create your own custom manager then you can use the manager_helper_template which is under the Resources while creating a script. The manager that is going to be referenced MUST be the only one that calls the method void set_manager(manager) and provides self as reference. Other scripts using this manager helper resource reference MUST only call the method get_manager() and then use the manager's methods from there. You can check out the script cop_update_manager_global_helper to see how the manager resource script is coded.

  • COP_PoolHelper - This manager's reference type stores and uses any script that is a child of base_pool. For now the scripts pool_global and pool_local can be stored and used by this reference helper script.
  • COP_UpdateManagerGlobalHelper - This manager's reference type stores and uses any script that is a child of base_update_manager. For now the scripts physics_process_manager_local, physics_process_manager_global, process_manager_local and process_manager_global can be stored and used by this reference helper script.
  • manager_helper_template - For creating a new COP_Helper type you can simply use the script templates that are already present in the addon. Go to the folder addons -> kamran_wali -> code_opt_pro and then copy the folder script_templates. Paste the copy folder to the root folder res://. Now you can use the script templates to create a new COP_Helper. Just create a new script and make sure to Inherit from Resource. Then in the Template section select Resource: Manager Helper Template. Give the script any name you want and finally create it. Now in the script make sure to give it a class name if you want to which has been commented out. For the _manager, change it to any script type you want. For the get_manager() method make sure to give it a return type as well which may help with performance a bit. Finally for the set_manager(manager) method make sure the parameter has a type as well which may also help with performance.

Observers

This category shares different type of observers like bool, float, int and String. The variables in this category uses the observer pattern to send signals to the observer. Basically when the value in the observer changes then it will emit that change to the observers. The emit is done using Godot's Signals. The observers are similar to the Vars but the only difference being that the observers can emit signals. Read the Vars to understand how the values are stored.

Clone this wiki locally