A+B: Difference between revisions

Content added Content deleted
(Add GDScript)
(→‎{{header|GDScript}}: Simplified to only do one line to properly match spec)
Line 2,918: Line 2,918:
extends Node
extends Node


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


var fields := value.split(" ", false) # Split by spaces
# For every line of input, append the sum as a string to the out array.
if len(fields) == 2: # Basic input validation
var out: Array[String] = [] # Array to store the lines of output
output = str(int(fields[0]) + int(fields[1]))
for line in value.split("\n"):
else: # Invalid input
var parts := line.split(" ", false)
var sum := 0
output = ""
for part in parts:
sum += int(part)
out.append(str(sum))


# Update the output property
@export var output: String
output = "\n".join(out)

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