Scripts and calls¶
Note
These entities come with the Gameplay entities pack, see Installing and customizing.
Point entities for what plain wiring cannot reach: game state, your own game code, animations, and finding out why a chain does not fire.
logic_script¶
Runs a GDScript snippet when fired, for a little logic no built in entity offers, like reading the player's health, without writing a custom entity.
- Inputs:
run(activator),run_with(parameter) - Outputs:
ran(result), with the snippet's return value - Keys:
sourceempty,expressionempty (a one liner, used whensourceis empty)
The snippet sees this (the entity itself), activator (whoever started the chain), parameter (the incoming
value), io (the TrenchDotIO helpers, for example to find entities by name) and tree (the SceneTree).
run_with always has a null activator. A compile error is logged as a warning when the map loads. This snippet hurts
the player:
var p = io.find_targets(this, "!player", null)
if not p.is_empty():
p[0].take_damage(25, this)
Warning
Indent nested lines with tabs. Spaces fail to compile with a mixed indentation error.
Warning
The snippet is code that comes inside the map. It runs whenever the game runs, with the same rights as the project's
own scripts, so treat a downloaded map that holds code like any program you download: it can do anything on your
computer. The Issues panel warns about every logic_script that holds code, every output that can hand one code and
every prefab with either, read those before you play the map.
logic_call¶
Calls a method on any target with fixed arguments, to reach your game code, such as adding score on a Game autoload.
Unlike a plain output it warns when the target or the method does not exist, so typos show up in the log. C# methods
work under their PascalCase names.
- Inputs:
trigger(activator),call_with(parameter) - Outputs:
called(result) - Keys:
call_target/root/Game,methodempty,arguments[]
call_target is a node path, a @group, a targetname, !activator or !self. arguments is a JSON array, like
["key_red", "$activator"], and takes the placeholders from Parameters, resolved on the
logic_call itself. call_with puts its parameter where "$parameter" stands, or passes it as the only argument.
logic_animate¶
Plays animations on the first AnimationPlayer at or under target, for characters and props that carry their own
animations. Set target to !activator to animate whoever started the chain.
- Inputs:
play(name),stop,queue(name),seek(time) - Outputs:
finished(anim) - Keys:
target!self,animationempty (played whenplayhas no name),speed1.0
logic_debug¶
Prints a line on write and shows its recent lines as a floating label in debug builds, so you can see in game whether
a chain reaches it and with what parameter. With trace_all on it logs every output in the game, a quick way to watch a
whole chain. See Debugging.
- Inputs:
write(parameter),toggle(the label),show,hide - Outputs:
printed(text) - Keys:
message{name} received {parameter} from {activator}({time}works too),show_label1,trace_all0