Properties
In this chapter you'll learn how to expose different types of Properties from a Jenova C++ Script.
Jenova allows you to expose various types of properties to the Godot Inspector and manipulate them directly in the game or editor. You can set these properties through the interface or use third-party languages like C#, GDScript, and Python etc.
Benefits of using Properties:
- Easily use resources in the scene such as Nodes, Textures, Audios etc. with Drag and Drop support.
- Avoid hardcoding values in your C++ Script.
- Adjust and test values within your game logic in real-time.
Note : You can get and set properties directly in your C++ Script like any other value.
Just remember, properties must be defined only in sub-types ofgodot::Variant
Note : Each script instance has its own unique properties; these properties can't be shared across different instances.
Basic Properties
To expose a property from your C++ Script, Simply add JENOVA_PROPERTY
inside the Script Block :
JENOVA_PROPERTY(double /* Type */, run_speed /* Name */, 200.0 /* Default Value */)
After compiling your project, you will see the property appear in the Inspector.
run_speed
and default value of 200.0
appeared.Here's an example :
// Class Name
JENOVA_CLASS_NAME("My C++ Script")
// Script Block Begin
JENOVA_SCRIPT_BEGIN
// Properties
JENOVA_PROPERTY(double, run_speed, 200.0)
// Callbacks
void OnProcess(double _delta)
{
Output("Run Speed : %lf", run_speed);
}
// Script Block End
JENOVA_SCRIPT_END
By compiling above script you will see this :
JENOVA_CLASS_NAME
property area gets a name.Now, If you run the game, You can modify the property in the Inspector and it will be updated in the Output on-the-fly.
Advanced Properties
The property definer macro JENOVA_PROPERTY
is dynamic. You can use more advanced property features in the following form :
JENOVA_PROPERTY(String, label_prefix, "Untitled", Group:"My Props", Usage:PROPERTY_USAGE_EDITOR)
Current valid extra parameters are Group
, Hint
, HintString
, Usage
and they can be used in any order.
Here's an example :
// Class Name
JENOVA_CLASS_NAME("My C++ Script")
// Script Block Begin
JENOVA_SCRIPT_BEGIN
// Properties
JENOVA_PROPERTY(String, label_prefix, "Untitled")
JENOVA_PROPERTY(double, label_value, 1.5f, Group:"Custom Props")
JENOVA_PROPERTY(Color, label_color, Color(1.0f, 0.5f, 0.5f, 1.0f))
...
// Script Block End
JENOVA_SCRIPT_END
By compiling above script you will see this :
label_value
is grouped in Custom Props
Here's a more advanced example :
// Class Name
JENOVA_CLASS_NAME("Dummy Controller")
// Script Block Begin
JENOVA_SCRIPT_BEGIN
// Properties
JENOVA_PROPERTY(int, dummy_state, 0, Hint:PROPERTY_HINT_ENUM, HintString:"Idle,Walk,Run", Usage:PROPERTY_USAGE_EDITOR)
// Script Block End
JENOVA_SCRIPT_END
By compiling above script you will see this :
Dummy State
property with advanced parameters.Resources & References
Tip : Properties will be updated at Debug Mode when changed from editor!
Since the Jenova Property Macro doesn't change the preprocessed source code and is only used by the Jenova Source Code Parser.
- Do not break Jenova Property Macro into multiple lines; It must be in one line.
- Do not mix flags in
Usage
parameter, as it's not supported yet.