Prefix Command
GDTerminal allows you to mark one saved command as a "Prefix" command, which means that its contents will be prepended before any other code you run.
As an example, if you set the prefix command to
print("Hello world!")
,
that print
statement will be prepended before all code that you run.
Running print("Goodbye world!")
would then print "Hello world!"
and "Goodbye world!"
in the output.
Usage
This feature can be used to store common variables or functions in a single place because they can then be accessed by anything you run.
# Prefix command
var selected_nodes = EditorInterface.get_selection().get_selected_nodes()
var is_control = func(node):
var selected_nodes = EditorInterface.get_selection().get_selected_nodes()
var is_control = func(node):
return node is Control
# Now "selected_nodes" and "is_control"
# can be accessed whenever you run code
for node in selected_nodes:
# can be accessed whenever you run code
for node in selected_nodes:
print(is_control.call(node))
Setting the Prefix Command
To set the prefix command, open the saved commands panel and rename a command to Prefix
.
Only the first command named Prefix will be used when running code - all others will be ignored.