-
Notifications
You must be signed in to change notification settings - Fork 1
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 4 categories of data share and each have their own different data types.
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.
- COP_FixedBoolVar - This FixedVar type shares bool data types. When creating the COP_FixedBoolVar set the value either true or false by clicking the tick box. To get the value simply call the method get_value(). To use COP_FixedBoolVar simply change the type of a var to COP_FixedBoolVar.
- COP_FixedFloatVar - This FixedVar type shares float data types. When creating the COP_FixedFloatVar set the value to any float type value. To get the value simply call the method get_value(). To use COP_FixedFloatVar simply change the type of a var to COP_FixedFloatVar.
- COP_FixedIntVar - This FixedVar type shares int data types. When creating the COP_FixedIntVar set the value to any int type value. To get the value simply call the method get_value(). To use COP_FixedIntVar simply change the type of a var to COP_FixedIntVar.
- COP_FixedStringVar - This FixedVar type shares String data types. When creating the COP_FixedStringVar set the value to any String type value. To get the value simply call the method get_value(). To use COP_FixedStringVar simply change the type of a var to COP_FixedStringVar.
- COP_FixedVector2Var - This FixedVar type shares Vector2 data types. When creating the COP_FixedVector2Var set the value to any Vector2 type value. To get the value simply call the method get_value(). To use COP_FixedVector2Var simply change the type of a var to COP_FixedVector2Var.
- COP_FixedVector3Var - This FixedVar type shares Vector3 data types. When creating the COP_FixedVector3Var set the value to any Vector3 type value. To get the value simply call the method get_value(). To use COP_FixedVector3Var simply change the type of a var to COP_FixedVector3Var.
- fixed_var_template - For creating a new COP_FixedVar 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 copied folder to the root folder res://. Now you can use the script templates to create a new COP_FixedVar. Just create a new script and make sure to Inherit from Resource. Then in the Template section select Resource: Fixed Var 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 _value, change it to any type you want. Finally for the get_value() method make sure to give it a return type as well which may help with performance a bit.
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 copied 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.
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.
- COP_ObserverAction - This observer type has no data type. It only has a signal with no parameters. To emit the signal simply call action(). For removing all the callables from the observer simply call the method disconnect_all().
- COP_ObserverBool - This observer type shares and emits the bool data type. To add an observer simply connect to the signal value_changed(bool value). To set the value simply call set_value(bool). To set the value and emit it simply call set_value_emit(bool). To get the value just call bool get_value(). To get the value and emit it then just call bool get_value_emit(). For removing all the callables from the observer simply call the method disconnect_all().
- COP_ObserverFloat - This observer type shares and emits the float data type. To add an observer simply connect to the signal value_changed(float value). To set the value simply call void set_value(value). To set the value and emit it simply call void set_value_emit(value). To get the value just call float get_value(). To get the value and emit it then just call float get_value_emit(). For removing all the callables from the observer simply call the method disconnect_all().
- COP_ObserverInt - This observer type shares and emits the int data type. To add an observer simply connect to the signal value_changed(int value). To set the value simply call void set_value(value). To set the value and emit it simply call void set_value_emit(value). To get the value just call int get_value(). To get the value and emit it then just call int get_value_emit(). For removing all the callables from the observer simply call the method void disconnect_all().
- COP_ObserverString - This observer type shares and emits the String data type. To add an observer simply connect to the signal value_changed(String value). To set the value simply call void set_value(value). To set the value and emit it simply call void set_value_emit(value). To get the value just call get_value(). To get the value and emit it then just call get_value_emit(). For removing all the callables from the observer simply call the method void disconnect_all().
- COP_ObserverVector2 - This observer type shares and emits the Vector2 data type. To add an observer simply connect to the signal value_changed(Vector2 value). To set the value simply call void set_value(value). To set the value and emit it simply call void set_value_emit(value). To get the value just call get_value(). To get the value and emit it then just call get_value_emit(). For removing all the callables from the observer simply call the method void disconnect_all().
- COP_ObserverVector3 - This observer type shares and emits the Vector3 data type. To add an observer simply connect to the signal value_changed(Vector3 value)_. To set the value simply call void set_value(value). To set the value and emit it simply call void set_value_emit(value). To get the value just call get_value(). To get the value and emit it then just call get_value_emit(). For removing all the callables from the observer simply call the method void disconnect_all().
- observer_template - For creating a new COP_Observer 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 copied folder to the root folder res://. Now you can use the script templates to create a new COP_Observer. Just create a new script and make sure to Inherit from Resource. Then in the Template section select Resource: Observer 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 _value, change it to any type type you want. For the get_value and get_value_emit() methods make sure to give it a return type as well which may help with performance a bit. Finally for the set_value(value) and set_value_emit(value) method make sure the parameter has a type as well which may also help with performance.
Just like Fixed Vars this category shares different type of data types as well, example bool, float, int, string etc. The only difference is that you can NOT set any values here like Fixed Vars and the values may change through custom scripts. Vars basically share values that are constantly changing. For example - You have 5 objects that wants to know the player's position. Then just create a COP_Vector3Var and make the player script constantly update the newly created COP_Vector3Var. Then add the newly created COP_Vector3Var to the other 5 objects. Now all of those 5 objects have access to the player's position without the need of player script reference. Also use the functions get_value() and set_value(value) for getting and setting the value. Do NOT get or set the property _value directly through script as this may result in error later on. Below are all the types.
- COP_BoolVar - This Var type shares bool data types. To set the value simply call void set_value(value). To get the value just call get_value(). To use COP_BoolVar simply change the type of a var to COP_BoolVar.
- COP_Camera2DVar - This Var type shares Camera2D data types. To set the value simply call void set_value(value). To get the value just call get_value(). To use COP_Camera2DVar simply change the type of a var to COP_Camera2DVar.
- COP_Camera3DVar - This Var type shares Camera3D data types. To set the value simply call void set_value(value). To get the value just call get_value(). To use COP_Camera3DVar simply change the type of a var to COP_Camera3DVar.
- COP_FloatVar - This Var type shares float data types. To set the value simply call void set_value(value). To get the value just call get_value(). To use COP_FloatVar simply change the type of a var to COP_FloatVar.
- COP_IntVar - This Var type shares int data types. To set the value simply call void set_value(value). To get the value just call get_value(). To use COP_IntVar simply change the type of a var to COP_IntVar.
- COP_Node2DVar - This Var type shares Node2 data types. To set the value simply call void set_value(value). To get the value just call get_value(). To use COP_Node2DVar simply change the type of a var to COP_Node2DVar.
- COP_Node3DVar - This Var type shares Node3D data types. To set the value simply call void set_value(value). To get the value just call get_value(). To use COP_Node3DVar simply change the type of a var to COP_Node3DVar.
- COP_NodeVar - This Var type shares Node data types. To set the value simply call void set_value(value). To get the value just call get_value(). To use COP_NodeVar simply change the type of a var to COP_NodeVar.
- COP_StringVar - This Var type shares String data types. To set the value simply call void set_value(value). To get the value just call get_value(). To use COP_StringVar simply change the type of a var to COP_StringVar.
- COP_Vector2Var - This Var type shares Vector2 data types. To set the value simply call void set_value(value). To get the value just call get_value(). To use COP_Vector2Var simply change the type of a var to COP_Vector2Var.
- COP_Vector3Var - This Var type shares Vector3 data types. To set the value simply call void set_value(value). To get the value just call get_value(). To use COP_Vector3Var simply change the type of a var to COP_Vector3Var.
- var_template - For creating a new COP_Var 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 copied folder to the root folder res://. Now you can use the script templates to create a new COP_Var. Just create a new script and make sure to Inherit from Resource. Then in the Template section select Resource: Var 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 _value, change it to any type type you want. For the get_value method make sure to give it a return type as well which may help with performance a bit. Finally for the set_value(value) method make sure the parameter has a type as well which may also help with performance.
For now the only way to create a new variable is to use the Variable Creator plugin. You can open the Variable Creator window by going to the menu Project -> Project Settings then select the Plugins tab and finally enable the Variable Creator. This will open the Variable Creator by docking it at the bottom right side. You can dock it how ever you wish. Below I will explain the highlighted parts of the Variable Creator.
Variable Creator |
- a. Name - This is where you give the name of the variable you want to create. If name given already exists in the path then the newly created variable will replace the old one and it does not matter what type it was.
- b. Path - This is the path or folder location where the new variable will be created. You can update this path as well. Follow the instructions in c. to see how to update the path.
- c. Update Path - If you want to update the path where the new variable will be created then right click the folder where the variable should be created and select Copy Path. Paste the copied path in the path field, b.. Finally press the Update Path button and the path will be updated. This will only update the path for 1 variable type, in this case FixedBoolVar types. This way the Variable Creator will allow you to have different paths for different variable types. The default path is res://addons/kamran_wali/code_opt_pro/variables/.
- d. Category - This is where you get to select from which category the variable will be created. For now there are 4 categories which are FixedVars, Managers, Observers and Vars.
- e. Variable Type - This is where you get to select which type of variable to create. Each category have different type of variable types.
- f. Create Variable - This button will create the new variable type. Remember to give a name to the variable otherwise this button will NOT be visible. Also the name of the button Create Variable will change with the variable type selected so that you will know what type you are creating.
- Tutorial Bar
- Tutorial Debug
- Tutorial Instantiate Object
- Tutorial Pool
- Tutorial Timer
- Tutorial Update Manager
- Tutorial Variable Creator
- Bars
- Debugs
- Maths
- Pools
- Resources
- Fixed Vars
- Managers
- Observers
- Vars
- Script Templates
- Timers
- Updates