Script Effect
Retrieve AGM variables and switches by specific name in GDScript and print them to the console.
Key Points
- Create a Node-type node under GameObject and attach this script to it.
- In the Inspector panel, assign the VariableSettings and SwitchSettings nodes respectively.
- Assign
my_var_nameandmy_switch_nameto the names of the target variable and switch you are interested in. - In this example, the print action occurs in the
_readyfunction, so it will only print once. If it occurs in the_processor_physics_processfunction, it will print once per render frame or physics frame.
Core
extends Node
@export var variable_settings: VariableSettings
@export var switch_settings: SwitchSettings
func _ready() -> void:
if not variable_settings:
print_rich("[color=red][b]please assign VariableSettings node![/b][/color]")
if not switch_settings:
print_rich("[color=red][b]please assign SwitchSettings node![/b][/color]")
var my_var_name = "max_hp"
if variable_settings.has_value(my_var_name):
print(variable_settings.get_value(my_var_name))
else:
printerr("variable named '%s' does not exist!" % my_var_name)
var my_switch_name = "my_switch"
if switch_settings.has_value(my_switch_name):
print(switch_settings.get_value(my_switch_name))
else:
printerr("switch named '%s' does not exist!" % my_switch_name)