A+B: Difference between revisions

Content added Content deleted
(Add lang example)
(Add GDScript)
Line 2,909: Line 2,909:
<suma> =, eA + eB
<suma> =, eA + eB
</syntaxhighlight>

=={{header|GDScript}}==
Requires Godot 4. Runs as a tool script using the input and output properties. Does not check for zero lines of input.

<syntaxhighlight lang="gdscript">
@tool
extends Node

@export_multiline var input: String:
set(value):
input = value # Save the input field

# For every line of input, append the sum as a string to the out array.
var out: Array[String] = [] # Array to store the lines of output
for line in value.split("\n"):
var parts := line.split(" ", false)
var sum := 0
for part in parts:
sum += int(part)
out.append(str(sum))

# Update the output property
output = "\n".join(out)

@export_multiline var output: String
</syntaxhighlight>
</syntaxhighlight>