Menu
CoddyTech

Text and Comments

Lesson 2 of 48 in Coddy's GDScript for Lua Developers course.

A Lua chunk runs its top-level statements when loaded. GDScript statements execute inside methods; the supplied Node enters _ready(). Lua starts line comments with --, while GDScript uses #. Both print functions add a newline, but Lua separates arguments with tabs and GDScript concatenates them without a separator. Format a single string when output spacing is part of a contract. The Lua example uses io.write to specify spaces exactly. In tasks, helpers return text and the locked main prints it once. A comment marker inside a quoted string remains data.

Complete Lua 5.1 comparison. Run main.lua from the directory containing all shown files:

Lua file main.lua:

io.write("tag ", 7, "\n")
print("# data")

Lua output:

tag 7
# data

GDScript file main.gd:

extends Node

func _ready() -> void:
	print("tag", 7)
	print("# data")

GDScript output:

tag7
# data
challenge icon

Challenge

Easy

Return the exact text item=<name>;count=<n>. Inputs are a name and an integer. Do not print in the helper.

Input is one JSON array on stdin. The locked main parses it, calls the public APIs and prints result= followed by the returned text and a newline. No helper should print. Independent fixed probes verify required API behavior before the input case; they do not enforce implementation style.

Your code goes in exercise.gd. The supplied main.gd cannot be edited. Keep each class_name type in its named file.

Try it yourself

extends Node

func contract_ok(data: Array) -> bool:

	return true

func _ready() -> void:
	var data: Array = JSON.parse_string(OS.read_string_from_stdin())
	if not contract_ok(data):
		print("API_CONTRACT_FAILED")
		return
	print("result=" + Exercise.solve(data))
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in GDScript for Lua Developers

Practice on your own: Online GDScript compiler