Script Effect
Retrieve specific AGMaker variables and switches by name in GDScript and print them to the console.
Key Points
- Create a Node type node under GameObject and attach this script to it.
- Specify the VariableSettings and SwitchSettings nodes in the inspector panel.
- Assign
my_var_name
andmy_switch_name
to the names of the target variable and switch you are interested in. - In this example, the printing occurs in the
_ready
function, so it will only print once. If it occurs in the_process
or_physics_process
function, 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)