Mobile Game 29 · Animate the beam after each turn

Museum of Lost Lights · Lesson 29 of 50 · Intermediate to advanced · About 34 min

Give players feedback right after a tap. The mirrors and exhibit count should respond instantly, while the light grows from a faint glow to full brightness. Motion draws attention to the change.

A gouache painting of a Space Gallery with celestial exhibits, a midnight-blue floor and a domed ceiling.
What you’ll make Fade a newly routed beam into view while keeping puzzle decisions immediate.

Download the projects from the course page. In Godot’s Project Manager, choose Import, select project.godot, and use Run Project (F5). Start from checkpoints/28 when the lesson builds on prior work, or copy the checkpoints/29 folder to try this lesson on its own. Read the file names in the steps before editing.

Handle the tap. Flip the mirror and immediately trace the puzzle. → Reset visual brightness. Start the new beam faint. → Tween to full brightness. Adjust only the visual property for 0.32 seconds. → Redraw on change. The latest route fades in.
Handle the tap → Reset visual brightness → Tween to full brightness → Redraw on change

Build it step by step

Language and tools in this lesson Tween, create_tween, tween_property, set property, queue_redraw, if, null, short-circuit and.

  1. Give the beam its own display value

    Open main.gd and find the variables above _ready. Add a brightness value that starts at 1.0, then look at the set block under that property.

    var beam_brightness := 1.0:

    Why it works Brightness is a visual value. Zero is invisible and one is full glow. The set block runs when that value changes.

  2. Request a frame when the property changes

    In the set block, store value in beam_brightness and call queue_redraw. Read the line that multiplies glow opacity by the same brightness.

    queue_redraw()

    Why it works Setting the numeric property alone does not paint a new frame. Queue_redraw tells Godot to call _draw again. Scaling opacity makes all layers change together.

  3. Start a fresh tween

    Find _flash_beam. After cancelling any old animation, set brightness to 0.0 and create a tween. Add the tween_property call for 1.0 over 0.32 seconds.

    glow_tween.tween_property(self, "beam_brightness", 1.0, 0.32)

    Why it works A tween changes a value between two points over time. Godot runs this animation, so the script can respond to a new input during the fade.

  4. Handle a second tap safely

    Check both glow_tween != null and glow_tween.is_valid before killing it. The right-hand check runs only when the tween exists. Test two fast taps in a row.

    if glow_tween != null and glow_tween.is_valid():

    Why it works Stopping the old tween keeps two animations from trying to set the same property. The new click gets its own fade to reflect the most recent route.

  5. Keep puzzle rules before animation

    In _turn_tile, check that _refresh runs before _flash_beam. While the beam is fading, look at the awake count or turn a second tile.

    _flash_beam()

    Why it works The game updates its actual route and count immediately. The tween changes only how the result is presented. The player never has to wait for a rule to finish animating.

  6. Try a more comfortable speed

    In a copy, change 0.32 to 0.7 and compare. Keep the version you can follow without waiting for a long visual effect.

    Why it works Testing motion at different speeds teaches you to balance feedback with player control.

Watch the values change

  1. Tap the splitter. The room refreshes the route and sets visual brightness to 0.
    What you see. The count changes immediately.
  2. Wait about a third of a second. Tween brings brightness towards 1 and queues redraws.
    What you see. The new route becomes fully visible.
  3. Tap twice quickly. The old tween is cancelled before the next starts.
    What you see. The last route wins and the beam reaches full brightness.

Predict before you run Should the jelly count change when the fade ends or immediately after the tap?

Reveal the answer

Immediately after the tap. The fade is visual feedback. The game state has already been updated.

Complete checkpoint

Each tap changes the puzzle instantly and fades the new beam into view. Quick taps do not cause overlapping fades.

main.gd

extends Control

const STEPS: Array[Vector2i] = [Vector2i.UP, Vector2i.RIGHT, Vector2i.DOWN, Vector2i.LEFT]
const TURNS: Array = [[1, 0, 3, 2], [3, 2, 1, 0]]
const ORIGIN := Vector2(32, 139)
const PITCH := 78
const TILE := 70
const DEMO: Dictionary = {"title": "The sleepy jellies", "width": 6, "height": 4, "source": 6, "direction": 1, "mirrors": {}, "splitters": {"9": 0}, "targets": [11, 21], "walls": []}
const BACKDROP: Texture2D = preload("res://ocean_backdrop.svg")
const LANTERN: Texture2D = preload("res://lantern.svg")
const JELLY: Texture2D = preload("res://moon_jelly.svg")
var level: Dictionary
var turns: Dictionary = {}
var beam: Dictionary
var tile_buttons: Dictionary = {}
var board_layer: Control
var status: Label
var cards: Array
var history: Array[Dictionary] = []
var undo: Button
var glow_tween: Tween
var beam_brightness := 1.0:
	set(value):
		beam_brightness = value
		queue_redraw()

func _ready() -> void:
	_add_label(Vector2(31, 21), "MUSEUM OF LOST LIGHTS", 29)
	_add_label(Vector2(32, 64), "Animate the beam after each turn", 15)
	status = _add_label(Vector2(576, 174), "", 17)
	status.custom_minimum_size = Vector2(302, 141)
	status.autowrap_mode = TextServer.AUTOWRAP_WORD_SMART
	cards = _read_cards()
	var picker := OptionButton.new()
	picker.position = Vector2(575, 109)
	picker.custom_minimum_size = Vector2(286, 42)
	for card in cards:
		picker.add_item(str(card.title))
	picker.item_selected.connect(_choose_card)
	add_child(picker)
	undo = Button.new()
	undo.text = "Undo one turn"
	undo.position = Vector2(575, 319)
	undo.custom_minimum_size = Vector2(133, 45)
	undo.pressed.connect(_undo_turn)
	add_child(undo)
	var restart := Button.new()
	restart.text = "Restart room"
	restart.position = Vector2(716, 319)
	restart.custom_minimum_size = Vector2(145, 45)
	restart.pressed.connect(_restart_room)
	add_child(restart)
	var hint := Button.new()
	hint.text = "Find a hint"
	hint.position = Vector2(575, 373)
	hint.custom_minimum_size = Vector2(133, 45)
	hint.pressed.connect(_hint)
	add_child(hint)
	board_layer = Control.new()
	board_layer.mouse_filter = Control.MOUSE_FILTER_IGNORE
	add_child(board_layer)
	_load_level(cards[0])

func _add_label(at: Vector2, text: String, text_size: int) -> Label:
	var label := Label.new()
	label.position = at
	label.text = text
	label.add_theme_font_size_override("font_size", text_size)
	label.add_theme_color_override("font_color", Color("#fff1d4"))
	add_child(label)
	return label

func _load_level(data: Dictionary) -> void:
	level = data
	turns.clear()
	history.clear()
	tile_buttons.clear()
	for child in board_layer.get_children():
		child.queue_free()
	for tile in range(int(level.width) * int(level.height)):
		var is_mirror := _turn_at(level.mirrors, tile) >= 0
		var is_splitter := _turn_at(level.splitters, tile) >= 0
		if is_mirror or is_splitter:
			var button := Button.new()
			button.position = _cell(tile)
			button.size = Vector2(TILE, TILE)
			button.tooltip_text = "Rotate " + ("splitter" if is_splitter else "mirror")
			button.pressed.connect(_turn_tile.bind(tile))
			board_layer.add_child(button)
			tile_buttons[tile] = button
	_refresh()

func _turn_at(layout: Dictionary, tile: int) -> int:
	return int(layout.get(str(tile), -1))

func _orientation(tile: int, state: Dictionary) -> int:
	var start := _turn_at(level.mirrors, tile)
	if start < 0:
		start = _turn_at(level.splitters, tile)
	return int(state.get(tile, start))

func _turn_tile(tile: int) -> void:
	history.append(turns.duplicate())
	turns[tile] = 1 - _orientation(tile, turns)
	_refresh()
	_flash_beam()

func _trace(state: Dictionary) -> Dictionary:
	var segments: Array[Vector2i] = []
	var lit: Array[int] = []
	var loop_found := false
	var pending: Array[Dictionary] = [{"ray": Vector2i(int(level.source), int(level.direction)), "seen": {}}]
	while not pending.is_empty():
		var item: Dictionary = pending.pop_front()
		var ray: Vector2i = item.ray
		var seen: Dictionary = item.seen
		if seen.has(ray):
			loop_found = true
			continue
		var trail := seen.duplicate()
		trail[ray] = true
		var tile := ray.x
		var direction := ray.y
		var coordinates := Vector2i(tile % int(level.width), floori(float(tile) / int(level.width)))
		var next_position := coordinates + STEPS[direction]
		if not Rect2i(0, 0, int(level.width), int(level.height)).has_point(next_position):
			continue
		var next_tile := next_position.y * int(level.width) + next_position.x
		segments.append(Vector2i(tile, next_tile))
		if level.targets.has(next_tile) and not lit.has(next_tile):
			lit.append(next_tile)
		if level.walls.has(next_tile):
			continue
		var splitter := _turn_at(level.splitters, next_tile)
		if splitter >= 0:
			pending.append({"ray": Vector2i(next_tile, direction), "seen": trail})
			var branch: int = TURNS[_orientation(next_tile, state)][direction]
			pending.append({"ray": Vector2i(next_tile, branch), "seen": trail})
		else:
			var mirror := _turn_at(level.mirrors, next_tile)
			var onward: int = TURNS[_orientation(next_tile, state)][direction] if mirror >= 0 else direction
			pending.append({"ray": Vector2i(next_tile, onward), "seen": trail})
	return {"segments": segments, "lit": lit, "loop": loop_found}

func _refresh() -> void:
	beam = _trace(turns)
	for tile in tile_buttons:
		var mirrored := _orientation(tile, turns)
		var button: Button = tile_buttons[tile]
		var glyph := "/" if mirrored == 0 else "\\"
		button.text = ("Split " if _turn_at(level.splitters, tile) >= 0 else "") + glyph
	var complete: bool = beam.lit.size() == level.targets.size()
	var message := "All exhibits awake!" if complete else "Tap a mirror or splitter to turn it."
	if beam.loop:
		message = "A ray repeated a step. Turn the splitter to break the loop."
	status.text = "%s\n\nExhibits awake: %d of %d\n%s" % [level.title, beam.lit.size(), level.targets.size(), message]
	undo.disabled = history.is_empty()
	queue_redraw()

func _cell(tile: int) -> Vector2:
	var col := tile % int(level.width)
	var row := floori(float(tile) / int(level.width))
	return ORIGIN + Vector2(col, row) * PITCH

func _center(tile: int) -> Vector2:
	return _cell(tile) + Vector2(TILE * 0.5, TILE * 0.5)

func _draw() -> void:
	draw_rect(Rect2(Vector2.ZERO, Vector2(900, 540)), Color("#132b3c"))
	draw_texture_rect(BACKDROP, Rect2(0, 65, 900, 475), false)
	draw_rect(Rect2(19, 102, 490, 360), Color(0.05, 0.11, 0.17, 0.82))
	if level.is_empty():
		return
	for column in range(int(level.width)):
		draw_string(ThemeDB.fallback_font, _cell(column) + Vector2(30, -8), str(column + 1), HORIZONTAL_ALIGNMENT_LEFT, -1, 13, Color("#f0d096"))
	for row in range(int(level.height)):
		draw_string(ThemeDB.fallback_font, _cell(row * int(level.width)) + Vector2(-17, 43), str(row + 1), HORIZONTAL_ALIGNMENT_LEFT, -1, 13, Color("#f0d096"))
	for tile in range(int(level.width) * int(level.height)):
		var box := Rect2(_cell(tile), Vector2(TILE, TILE))
		draw_rect(box, Color("#1d4859"))
		draw_rect(box, Color("#63858b"), false, 1.0)
		if tile == int(level.source):
			draw_texture_rect(LANTERN, box.grow(-1.0), false)
		elif level.targets.has(tile):
			var awake: bool = beam.get("lit", []).has(tile)
			var tint := Color.WHITE if awake else Color(0.50, 0.66, 0.80, 0.65)
			draw_texture_rect(JELLY, box.grow(-3.0), false, tint)
	for segment in beam.get("segments", []):
		var start := _center(segment.x)
		var finish := _center(segment.y)
		draw_line(start, finish, Color(0.36, 0.97, 0.82, 0.25 * beam_brightness), 14.0, true)
		draw_line(start, finish, Color(0.46, 0.87, 0.81, beam_brightness), 6.0, true)
		draw_line(start, finish, Color(0.90, 1.0, 0.95, beam_brightness), 2.0, true)


func _read_cards() -> Array:
	var file := FileAccess.open("res://gallery.json", FileAccess.READ)
	if file == null:
		return [DEMO]
	var parsed: Variant = JSON.parse_string(file.get_as_text())
	if not parsed is Array:
		return [DEMO]
	var good_cards: Array = []
	for card in parsed:
		if _valid_card(card):
			good_cards.append(_normalise_card(card))
	return good_cards if not good_cards.is_empty() else [DEMO]

func _normalise_card(source: Dictionary) -> Dictionary:
	var card := source.duplicate()
	for key in ["targets", "walls"]:
		var tiles: Array[int] = []
		for tile in card[key]:
			tiles.append(int(tile))
		card[key] = tiles
	return card

func _valid_card(card: Variant) -> bool:
	if not card is Dictionary:
		return false
	for key in ["title", "width", "height", "source", "direction", "mirrors", "splitters", "targets", "walls"]:
		if not card.has(key):
			return false
	if not card.title is String or card.width != 6 or card.height != 4:
		return false
	if not card.mirrors is Dictionary or not card.splitters is Dictionary:
		return false
	if not card.targets is Array or not card.walls is Array or card.targets.is_empty():
		return false
	if not _whole_in(card.source, 24) or not _whole_in(card.direction, 4):
		return false
	for key in card.mirrors.keys() + card.splitters.keys():
		if not str(key).is_valid_int() or not _whole_in(int(key), 24):
			return false
	for value in card.mirrors.values() + card.splitters.values():
		if not _whole_in(value, 2):
			return false
	for tile in card.targets + card.walls:
		if not _whole_in(tile, 24):
			return false
	return true

func _whole_in(value: Variant, limit: int) -> bool:
	if not (value is int or value is float):
		return false
	return float(value) == floorf(float(value)) and value >= 0 and value < limit

func _choose_card(index: int) -> void:
	_load_level(cards[index])

func _undo_turn() -> void:
	if history.is_empty():
		return
	turns = history.pop_back()
	_refresh()

func _restart_room() -> void:
	_load_level(level)

func _key(state: Dictionary, knobs: Array) -> String:
	var key := ""
	for tile in knobs:
		key += str(_orientation(tile, state))
	return key

func _best_next_turn() -> int:
	if beam.lit.size() == level.targets.size():
		return -2
	var knobs := tile_buttons.keys()
	if knobs.size() > 8:
		return -1
	var queue: Array[Dictionary] = [{"turns": turns.duplicate(), "first": -1}]
	var visited: Dictionary = {_key(turns, knobs): true}
	while not queue.is_empty():
		var candidate: Dictionary = queue.pop_front()
		var state: Dictionary = candidate.turns
		if _trace(state).lit.size() == level.targets.size():
			return int(candidate.first)
		for tile in knobs:
			var neighbour := state.duplicate()
			neighbour[tile] = 1 - _orientation(tile, state)
			var key := _key(neighbour, knobs)
			if visited.has(key):
				continue
			visited[key] = true
			var first := int(candidate.first) if candidate.first >= 0 else int(tile)
			queue.append({"turns": neighbour, "first": first})
	return -1

func _hint() -> void:
	var tile := _best_next_turn()
	if tile == -2:
		status.text = "The exhibits are already awake."
		return
	if tile < 0:
		status.text = "No hint available for this layout."
		return
	var row := floori(float(tile) / int(level.width)) + 1
	var col := tile % int(level.width) + 1
	status.text = "Try row %d, column %d. This keeps you on a shortest route." % [row, col]

func _flash_beam() -> void:
	if glow_tween != null and glow_tween.is_valid():
		glow_tween.kill()
	beam_brightness = 0.0
	glow_tween = create_tween()
	glow_tween.tween_property(self, "beam_brightness", 1.0, 0.32)

gallery.json

[
  {
    "title": "The sleepy jellies",
    "width": 6,
    "height": 4,
    "source": 6,
    "direction": 1,
    "mirrors": {},
    "splitters": {
      "9": 0
    },
    "targets": [
      11,
      21
    ],
    "walls": []
  },
  {
    "title": "The returning ray",
    "width": 6,
    "height": 4,
    "source": 8,
    "direction": 1,
    "mirrors": {
      "7": 0,
      "13": 1,
      "15": 0
    },
    "splitters": {
      "9": 1
    },
    "targets": [
      3,
      11
    ],
    "walls": []
  }
]

GDScript line by line

Follow the line numbers, including the indent at the start of each line. Find the code the game will run first, then look for the function that reacts when you tap or change something.

Read main.gd line by line
  1. extends ControlStarts with Godot's Control type. This script gets the abilities of that type and adds the game's own rules.
  2. const STEPS: Array[Vector2i] = [Vector2i.UP, Vector2i.RIGHT, Vector2i.DOWN, Vector2i.LEFT]Creates a constant named STEPS. The expression makes a list whose items keep their order. The type after the colon says what kind of value it can hold.
  3. const TURNS: Array = [[1, 0, 3, 2], [3, 2, 1, 0]]Creates a constant named TURNS. The expression makes a list whose items keep their order. The type after the colon says what kind of value it can hold.
  4. const ORIGIN := Vector2(32, 139)Creates a constant named ORIGIN. The expression packs x and y into one value. Godot infers the type from the first value.
  5. const PITCH := 78Creates a constant named PITCH. The expression uses the whole number 78. Godot infers the type from the first value.
  6. const TILE := 70Creates a constant named TILE. The expression uses the whole number 70. Godot infers the type from the first value.
  7. const DEMO: Dictionary = {"title": "The sleepy jellies", "width": 6, "height": 4, "source": 6, "direction": 1, "mirrors": {}, "splitters": {"9": 0}, "targets": [11, 21], "walls": []}Creates a constant named DEMO. The expression makes a dictionary that looks up values by key. The type after the colon says what kind of value it can hold.
  8. const BACKDROP: Texture2D = preload("res://ocean_backdrop.svg")Creates a constant named BACKDROP. The expression prepares a resource at a fixed project path when the script is loaded. The type after the colon says what kind of value it can hold.
  9. const LANTERN: Texture2D = preload("res://lantern.svg")Creates a constant named LANTERN. The expression prepares a resource at a fixed project path when the script is loaded. The type after the colon says what kind of value it can hold.
  10. const JELLY: Texture2D = preload("res://moon_jelly.svg")Creates a constant named JELLY. The expression prepares a resource at a fixed project path when the script is loaded. The type after the colon says what kind of value it can hold.
  11. var level: DictionaryDeclares level for later use. A colon followed by a type says which kind of value belongs here.
  12. var turns: Dictionary = {}Creates a variable named turns. The expression makes a dictionary that looks up values by key. The type after the colon says what kind of value it can hold.
  13. var beam: DictionaryDeclares beam for later use. A colon followed by a type says which kind of value belongs here.
  14. var tile_buttons: Dictionary = {}Creates a variable named tile_buttons. The expression makes a dictionary that looks up values by key. The type after the colon says what kind of value it can hold.
  15. var board_layer: ControlDeclares board_layer for later use. A colon followed by a type says which kind of value belongs here.
  16. var status: LabelDeclares status for later use. A colon followed by a type says which kind of value belongs here.
  17. var cards: ArrayDeclares cards for later use. A colon followed by a type says which kind of value belongs here.
  18. var history: Array[Dictionary] = []Creates a variable named history. The expression makes a list whose items keep their order. The type after the colon says what kind of value it can hold.
  19. var undo: ButtonDeclares undo for later use. A colon followed by a type says which kind of value belongs here.
  20. var glow_tween: TweenDeclares glow_tween for later use. A colon followed by a type says which kind of value belongs here.
  21. var beam_brightness := 1.0:Creates a variable named beam_brightness. The expression reads 1.0:. Godot infers the type from the first value.
  22. set(value):Runs special instructions when code changes or reads this property.
  23. beam_brightness = valueStores the new value in beam_brightness. The expression reads value.
  24. queue_redraw()Asks Godot to call _draw again on a later frame so the screen matches the new state.
  25. func _ready() -> void:Godot calls this once after the scene and its children are ready. Use it to set up the room and connect controls.
  26. _add_label(Vector2(31, 21), "MUSEUM OF LOST LIGHTS", 29)Calls _add_label with the values in its parentheses.
  27. _add_label(Vector2(32, 64), "Animate the beam after each turn", 15)Calls _add_label with the values in its parentheses.
  28. status = _add_label(Vector2(576, 174), "", 17)Stores the new value in status. The expression calls _add_label with the values in its parentheses.
  29. status.custom_minimum_size = Vector2(302, 141)Updates status.custom_minimum_size, which controls the smallest space the layout should reserve for this control. The expression packs x and y into one value.
  30. status.autowrap_mode = TextServer.AUTOWRAP_WORD_SMARTStores the new value in status.autowrap_mode. The expression reads TextServer.AUTOWRAP_WORD_SMART.
  31. cards = _read_cards()Stores the new value in cards. The expression calls _read_cards with the values in its parentheses.
  32. var picker := OptionButton.new()Creates a variable named picker. The expression creates a new OptionButton object. Godot infers the type from the first value.
  33. picker.position = Vector2(575, 109)Updates picker.position, which controls the node's local x and y location. The expression packs x and y into one value.
  34. picker.custom_minimum_size = Vector2(286, 42)Updates picker.custom_minimum_size, which controls the smallest space the layout should reserve for this control. The expression packs x and y into one value.
  35. for card in cards:Repeats the indented instructions for each value in cards.
  36. picker.add_item(str(card.title))Calls picker.add_item with the values in its parentheses.
  37. picker.item_selected.connect(_choose_card)Links a signal to the function that should run when the event happens.
  38. add_child(picker)Adds the new node to the scene tree so that Godot can run and draw it.
  39. undo = Button.new()Stores the new value in undo. The expression creates a new Button object.
  40. undo.text = "Undo one turn"Updates undo.text, which controls the words a player sees. The expression uses the text inside the quotes.
  41. undo.position = Vector2(575, 319)Updates undo.position, which controls the node's local x and y location. The expression packs x and y into one value.
  42. undo.custom_minimum_size = Vector2(133, 45)Updates undo.custom_minimum_size, which controls the smallest space the layout should reserve for this control. The expression packs x and y into one value.
  43. undo.pressed.connect(_undo_turn)Links a signal to the function that should run when the event happens.
  44. add_child(undo)Adds the new node to the scene tree so that Godot can run and draw it.
  45. var restart := Button.new()Creates a variable named restart. The expression creates a new Button object. Godot infers the type from the first value.
  46. restart.text = "Restart room"Updates restart.text, which controls the words a player sees. The expression uses the text inside the quotes.
  47. restart.position = Vector2(716, 319)Updates restart.position, which controls the node's local x and y location. The expression packs x and y into one value.
  48. restart.custom_minimum_size = Vector2(145, 45)Updates restart.custom_minimum_size, which controls the smallest space the layout should reserve for this control. The expression packs x and y into one value.
  49. restart.pressed.connect(_restart_room)Links a signal to the function that should run when the event happens.
  50. add_child(restart)Adds the new node to the scene tree so that Godot can run and draw it.
  51. var hint := Button.new()Creates a variable named hint. The expression creates a new Button object. Godot infers the type from the first value.
  52. hint.text = "Find a hint"Updates hint.text, which controls the words a player sees. The expression uses the text inside the quotes.
  53. hint.position = Vector2(575, 373)Updates hint.position, which controls the node's local x and y location. The expression packs x and y into one value.
  54. hint.custom_minimum_size = Vector2(133, 45)Updates hint.custom_minimum_size, which controls the smallest space the layout should reserve for this control. The expression packs x and y into one value.
  55. hint.pressed.connect(_hint)Links a signal to the function that should run when the event happens.
  56. add_child(hint)Adds the new node to the scene tree so that Godot can run and draw it.
  57. board_layer = Control.new()Stores the new value in board_layer. The expression creates a new Control object.
  58. board_layer.mouse_filter = Control.MOUSE_FILTER_IGNOREUpdates board_layer.mouse_filter, which controls how this control participates in pointer and touch input. The expression reads Control.MOUSE_FILTER_IGNORE.
  59. add_child(board_layer)Adds the new node to the scene tree so that Godot can run and draw it.
  60. _load_level(cards[0])Calls _load_level with the values in its parentheses.
  61. func _add_label(at: Vector2, text: String, text_size: int) -> Label:Defines add label, a reusable set of instructions. Parameters between the parentheses receive inputs. A return type after the arrow tells you which kind of result to expect.
  62. var label := Label.new()Creates a variable named label. The expression creates a new Label object. Godot infers the type from the first value.
  63. label.position = atUpdates label.position, which controls the node's local x and y location. The expression reads at.
  64. label.text = textUpdates label.text, which controls the words a player sees. The expression reads text.
  65. label.add_theme_font_size_override("font_size", text_size)Calls label.add_theme_font_size_override with the values in its parentheses.
  66. label.add_theme_color_override("font_color", Color("#fff1d4"))Calls label.add_theme_color_override with the values in its parentheses.
  67. add_child(label)Adds the new node to the scene tree so that Godot can run and draw it.
  68. return labelFinishes the function and hands its result back to the caller. The expression reads label.
  69. func _load_level(data: Dictionary) -> void:Defines load level, a reusable set of instructions. Parameters between the parentheses receive inputs. A return type after the arrow tells you which kind of result to expect.
  70. level = dataStores the new value in level. The expression reads data.
  71. turns.clear()Empties this collection.
  72. history.clear()Empties this collection.
  73. tile_buttons.clear()Empties this collection.
  74. for child in board_layer.get_children():Repeats the indented instructions for each value in board_layer.get_children().
  75. child.queue_free()Asks Godot to remove this node safely at the end of the frame.
  76. for tile in range(int(level.width) * int(level.height)):Repeats the indented instructions for each value in range(int(level.width) * int(level.height)).
  77. var is_mirror := _turn_at(level.mirrors, tile) >= 0Creates a variable named is_mirror. The expression calls _turn_at with the values in its parentheses. Godot infers the type from the first value.
  78. var is_splitter := _turn_at(level.splitters, tile) >= 0Creates a variable named is_splitter. The expression calls _turn_at with the values in its parentheses. Godot infers the type from the first value.
  79. if is_mirror or is_splitter:Checks is_mirror or is_splitter. The indented instructions below run only if this test passes.
  80. var button := Button.new()Creates a variable named button. The expression creates a new Button object. Godot infers the type from the first value.
  81. button.position = _cell(tile)Updates button.position, which controls the node's local x and y location. The expression calls _cell with the values in its parentheses.
  82. button.size = Vector2(TILE, TILE)Updates button.size, which controls the control's width and height. The expression packs x and y into one value.
  83. button.tooltip_text = "Rotate " + ("splitter" if is_splitter else "mirror")Stores the new value in button.tooltip_text. The expression chooses one of two values by checking the condition in the middle.
  84. button.pressed.connect(_turn_tile.bind(tile))Links a signal to the function that should run when the event happens.
  85. board_layer.add_child(button)Adds the new node to the scene tree so that Godot can run and draw it.
  86. tile_buttons[tile] = buttonStores the new value in tile_buttons[tile]. The expression reads button.
  87. _refresh()Calls _refresh with the values in its parentheses.
  88. func _turn_at(layout: Dictionary, tile: int) -> int:Defines turn at, a reusable set of instructions. Parameters between the parentheses receive inputs. A return type after the arrow tells you which kind of result to expect.
  89. return int(layout.get(str(tile), -1))Finishes the function and hands its result back to the caller. The expression converts a suitable value to a whole number.
  90. func _orientation(tile: int, state: Dictionary) -> int:Defines orientation, a reusable set of instructions. Parameters between the parentheses receive inputs. A return type after the arrow tells you which kind of result to expect.
  91. var start := _turn_at(level.mirrors, tile)Creates a variable named start. The expression calls _turn_at with the values in its parentheses. Godot infers the type from the first value.
  92. if start < 0:Checks start < 0. The indented instructions below run only if this test passes.
  93. start = _turn_at(level.splitters, tile)Stores the new value in start. The expression calls _turn_at with the values in its parentheses.
  94. return int(state.get(tile, start))Finishes the function and hands its result back to the caller. The expression converts a suitable value to a whole number.
  95. func _turn_tile(tile: int) -> void:Defines turn tile, a reusable set of instructions. Parameters between the parentheses receive inputs. A return type after the arrow tells you which kind of result to expect.
  96. history.append(turns.duplicate())Adds an item to the end of a list.
  97. turns[tile] = 1 - _orientation(tile, turns)Stores the new value in turns[tile]. The expression calculates a new value from the expressions on either side of the operator.
  98. _refresh()Calls _refresh with the values in its parentheses.
  99. _flash_beam()Calls _flash_beam with the values in its parentheses.
  100. func _trace(state: Dictionary) -> Dictionary:Defines trace, a reusable set of instructions. Parameters between the parentheses receive inputs. A return type after the arrow tells you which kind of result to expect.
  101. var segments: Array[Vector2i] = []Creates a variable named segments. The expression makes a list whose items keep their order. The type after the colon says what kind of value it can hold.
  102. var lit: Array[int] = []Creates a variable named lit. The expression makes a list whose items keep their order. The type after the colon says what kind of value it can hold.
  103. var loop_found := falseCreates a variable named loop_found. The expression uses the yes-or-no value false. Godot infers the type from the first value.
  104. var pending: Array[Dictionary] = [{"ray": Vector2i(int(level.source), int(level.direction)), "seen": {}}]Creates a variable named pending. The expression makes a list whose items keep their order. The type after the colon says what kind of value it can hold.
  105. while not pending.is_empty():Keeps repeating while not pending.is_empty() stays true. The loop body should eventually change the result or leave with break.
  106. var item: Dictionary = pending.pop_front()Creates a variable named item. The expression takes the first item out of the list and returns it. The type after the colon says what kind of value it can hold.
  107. var ray: Vector2i = item.rayCreates a variable named ray. The expression reads item.ray. The type after the colon says what kind of value it can hold.
  108. var seen: Dictionary = item.seenCreates a variable named seen. The expression reads item.seen. The type after the colon says what kind of value it can hold.
  109. if seen.has(ray):Checks seen.has(ray). The indented instructions below run only if this test passes.
  110. loop_found = trueStores the new value in loop_found. The expression uses the yes-or-no value true.
  111. continueSkips the rest of this turn through the loop and moves on to the next item.
  112. var trail := seen.duplicate()Creates a variable named trail. The expression copies the collection so a later change can leave the original alone. Godot infers the type from the first value.
  113. trail[ray] = trueStores the new value in trail[ray]. The expression uses the yes-or-no value true.
  114. var tile := ray.xCreates a variable named tile. The expression reads ray.x. Godot infers the type from the first value.
  115. var direction := ray.yCreates a variable named direction. The expression reads ray.y. Godot infers the type from the first value.
  116. var coordinates := Vector2i(tile % int(level.width), floori(float(tile) / int(level.width)))Creates a variable named coordinates. The expression packs whole-number x and y into one grid position. Godot infers the type from the first value.
  117. var next_position := coordinates + STEPS[direction]Creates a variable named next_position. The expression looks up the item or key written between the square brackets. Godot infers the type from the first value.
  118. if not Rect2i(0, 0, int(level.width), int(level.height)).has_point(next_position):Checks not Rect2i(0, 0, int(level.width), int(level.height)).has_point(next_position). The indented instructions below run only if this test passes.
  119. continueSkips the rest of this turn through the loop and moves on to the next item.
  120. var next_tile := next_position.y * int(level.width) + next_position.xCreates a variable named next_tile. The expression calculates a new value from the expressions on either side of the operator. Godot infers the type from the first value.
  121. segments.append(Vector2i(tile, next_tile))Adds an item to the end of a list.
  122. if level.targets.has(next_tile) and not lit.has(next_tile):Checks level.targets.has(next_tile) and not lit.has(next_tile). The indented instructions below run only if this test passes.
  123. lit.append(next_tile)Adds an item to the end of a list.
  124. if level.walls.has(next_tile):Checks level.walls.has(next_tile). The indented instructions below run only if this test passes.
  125. continueSkips the rest of this turn through the loop and moves on to the next item.
  126. var splitter := _turn_at(level.splitters, next_tile)Creates a variable named splitter. The expression calls _turn_at with the values in its parentheses. Godot infers the type from the first value.
  127. if splitter >= 0:Checks splitter >= 0. The indented instructions below run only if this test passes.
  128. pending.append({"ray": Vector2i(next_tile, direction), "seen": trail})Adds an item to the end of a list.
  129. var branch: int = TURNS[_orientation(next_tile, state)][direction]Creates a variable named branch. The expression looks up the item or key written between the square brackets. The type after the colon says what kind of value it can hold.
  130. pending.append({"ray": Vector2i(next_tile, branch), "seen": trail})Adds an item to the end of a list.
  131. else:Runs the indented fallback instructions if none of the earlier tests passed.
  132. var mirror := _turn_at(level.mirrors, next_tile)Creates a variable named mirror. The expression calls _turn_at with the values in its parentheses. Godot infers the type from the first value.
  133. var onward: int = TURNS[_orientation(next_tile, state)][direction] if mirror >= 0 else directionCreates a variable named onward. The expression chooses one of two values by checking the condition in the middle. The type after the colon says what kind of value it can hold.
  134. pending.append({"ray": Vector2i(next_tile, onward), "seen": trail})Adds an item to the end of a list.
  135. return {"segments": segments, "lit": lit, "loop": loop_found}Finishes the function and hands its result back to the caller. The expression makes a dictionary that looks up values by key.
  136. func _refresh() -> void:Defines refresh, a reusable set of instructions. Parameters between the parentheses receive inputs. A return type after the arrow tells you which kind of result to expect.
  137. beam = _trace(turns)Stores the new value in beam. The expression calls _trace with the values in its parentheses.
  138. for tile in tile_buttons:Repeats the indented instructions for each value in tile_buttons.
  139. var mirrored := _orientation(tile, turns)Creates a variable named mirrored. The expression calls _orientation with the values in its parentheses. Godot infers the type from the first value.
  140. var button: Button = tile_buttons[tile]Creates a variable named button. The expression looks up the item or key written between the square brackets. The type after the colon says what kind of value it can hold.
  141. var glyph := "/" if mirrored == 0 else "\\"Creates a variable named glyph. The expression chooses one of two values by checking the condition in the middle. Godot infers the type from the first value.
  142. button.text = ("Split " if _turn_at(level.splitters, tile) >= 0 else "") + glyphUpdates button.text, which controls the words a player sees. The expression chooses one of two values by checking the condition in the middle.
  143. var complete: bool = beam.lit.size() == level.targets.size()Creates a variable named complete. The expression counts the items in this collection. The type after the colon says what kind of value it can hold.
  144. var message := "All exhibits awake!" if complete else "Tap a mirror or splitter to turn it."Creates a variable named message. The expression chooses one of two values by checking the condition in the middle. Godot infers the type from the first value.
  145. if beam.loop:Checks beam.loop. The indented instructions below run only if this test passes.
  146. message = "A ray repeated a step. Turn the splitter to break the loop."Stores the new value in message. The expression uses the text inside the quotes.
  147. status.text = "%s\n\nExhibits awake: %d of %d\n%s" % [level.title, beam.lit.size(), level.targets.size(), message]Updates status.text, which controls the words a player sees. The expression uses the text inside the quotes.
  148. undo.disabled = history.is_empty()Updates undo.disabled, which controls whether the control should ignore activation. The expression calls history.is_empty with the values in its parentheses.
  149. queue_redraw()Asks Godot to call _draw again on a later frame so the screen matches the new state.
  150. func _cell(tile: int) -> Vector2:Defines cell, a reusable set of instructions. Parameters between the parentheses receive inputs. A return type after the arrow tells you which kind of result to expect.
  151. var col := tile % int(level.width)Creates a variable named col. The expression calculates a new value from the expressions on either side of the operator. Godot infers the type from the first value.
  152. var row := floori(float(tile) / int(level.width))Creates a variable named row. The expression calls floori with the values in its parentheses. Godot infers the type from the first value.
  153. return ORIGIN + Vector2(col, row) * PITCHFinishes the function and hands its result back to the caller. The expression calculates a new value from the expressions on either side of the operator.
  154. func _center(tile: int) -> Vector2:Defines center, a reusable set of instructions. Parameters between the parentheses receive inputs. A return type after the arrow tells you which kind of result to expect.
  155. return _cell(tile) + Vector2(TILE * 0.5, TILE * 0.5)Finishes the function and hands its result back to the caller. The expression calls _cell with the values in its parentheses.
  156. func _draw() -> void:Godot calls this when the node needs drawing. The instructions inside paint the current state.
  157. draw_rect(Rect2(Vector2.ZERO, Vector2(900, 540)), Color("#132b3c"))Paints a rectangle at the given position and size.
  158. draw_texture_rect(BACKDROP, Rect2(0, 65, 900, 475), false)Paints an image in a rectangle.
  159. draw_rect(Rect2(19, 102, 490, 360), Color(0.05, 0.11, 0.17, 0.82))Paints a rectangle at the given position and size.
  160. if level.is_empty():Checks level.is_empty(). The indented instructions below run only if this test passes.
  161. returnFinishes the function right here. Any later instructions in this function are skipped.
  162. for column in range(int(level.width)):Repeats the indented instructions for each value in range(int(level.width)).
  163. draw_string(ThemeDB.fallback_font, _cell(column) + Vector2(30, -8), str(column + 1), HORIZONTAL_ALIGNMENT_LEFT, -1, 13, Color("#f0d096"))Paints a piece of text with a font at a position measured from the node's origin.
  164. for row in range(int(level.height)):Repeats the indented instructions for each value in range(int(level.height)).
  165. draw_string(ThemeDB.fallback_font, _cell(row * int(level.width)) + Vector2(-17, 43), str(row + 1), HORIZONTAL_ALIGNMENT_LEFT, -1, 13, Color("#f0d096"))Paints a piece of text with a font at a position measured from the node's origin.
  166. for tile in range(int(level.width) * int(level.height)):Repeats the indented instructions for each value in range(int(level.width) * int(level.height)).
  167. var box := Rect2(_cell(tile), Vector2(TILE, TILE))Creates a variable named box. The expression describes a position and a size. Godot infers the type from the first value.
  168. draw_rect(box, Color("#1d4859"))Paints a rectangle at the given position and size.
  169. draw_rect(box, Color("#63858b"), false, 1.0)Paints a rectangle at the given position and size.
  170. if tile == int(level.source):Checks tile == int(level.source). The indented instructions below run only if this test passes.
  171. draw_texture_rect(LANTERN, box.grow(-1.0), false)Paints an image in a rectangle.
  172. elif level.targets.has(tile):If the earlier branches did not run, checks level.targets.has(tile) next.
  173. var awake: bool = beam.get("lit", []).has(tile)Creates a variable named awake. The expression looks up a named or indexed value, using a fallback when the call gives one. The type after the colon says what kind of value it can hold.
  174. var tint := Color.WHITE if awake else Color(0.50, 0.66, 0.80, 0.65)Creates a variable named tint. The expression chooses one of two values by checking the condition in the middle. Godot infers the type from the first value.
  175. draw_texture_rect(JELLY, box.grow(-3.0), false, tint)Paints an image in a rectangle.
  176. for segment in beam.get("segments", []):Repeats the indented instructions for each value in beam.get("segments", []).
  177. var start := _center(segment.x)Creates a variable named start. The expression calls _center with the values in its parentheses. Godot infers the type from the first value.
  178. var finish := _center(segment.y)Creates a variable named finish. The expression calls _center with the values in its parentheses. Godot infers the type from the first value.
  179. draw_line(start, finish, Color(0.36, 0.97, 0.82, 0.25 * beam_brightness), 14.0, true)Paints a line between two points with the chosen colour and width.
  180. draw_line(start, finish, Color(0.46, 0.87, 0.81, beam_brightness), 6.0, true)Paints a line between two points with the chosen colour and width.
  181. draw_line(start, finish, Color(0.90, 1.0, 0.95, beam_brightness), 2.0, true)Paints a line between two points with the chosen colour and width.
  182. func _read_cards() -> Array:Defines read cards, a reusable set of instructions. Parameters between the parentheses receive inputs. A return type after the arrow tells you which kind of result to expect.
  183. var file := FileAccess.open("res://gallery.json", FileAccess.READ)Creates a variable named file. The expression tries to open a file and returns a handle, or null if opening fails. Godot infers the type from the first value.
  184. if file == null:Checks file == null. The indented instructions below run only if this test passes.
  185. return [DEMO]Finishes the function and hands its result back to the caller. The expression makes a list whose items keep their order.
  186. var parsed: Variant = JSON.parse_string(file.get_as_text())Creates a variable named parsed. The expression tries to turn JSON text back into a value. The type after the colon says what kind of value it can hold.
  187. if not parsed is Array:Checks not parsed is Array. The indented instructions below run only if this test passes.
  188. return [DEMO]Finishes the function and hands its result back to the caller. The expression makes a list whose items keep their order.
  189. var good_cards: Array = []Creates a variable named good_cards. The expression makes a list whose items keep their order. The type after the colon says what kind of value it can hold.
  190. for card in parsed:Repeats the indented instructions for each value in parsed.
  191. if _valid_card(card):Checks _valid_card(card). The indented instructions below run only if this test passes.
  192. good_cards.append(_normalise_card(card))Adds an item to the end of a list.
  193. return good_cards if not good_cards.is_empty() else [DEMO]Finishes the function and hands its result back to the caller. The expression chooses one of two values by checking the condition in the middle.
  194. func _normalise_card(source: Dictionary) -> Dictionary:Defines normalise card, a reusable set of instructions. Parameters between the parentheses receive inputs. A return type after the arrow tells you which kind of result to expect.
  195. var card := source.duplicate()Creates a variable named card. The expression copies the collection so a later change can leave the original alone. Godot infers the type from the first value.
  196. for key in ["targets", "walls"]:Repeats the indented instructions for each value in ["targets", "walls"].
  197. var tiles: Array[int] = []Creates a variable named tiles. The expression makes a list whose items keep their order. The type after the colon says what kind of value it can hold.
  198. for tile in card[key]:Repeats the indented instructions for each value in card[key].
  199. tiles.append(int(tile))Adds an item to the end of a list.
  200. card[key] = tilesStores the new value in card[key]. The expression reads tiles.
  201. return cardFinishes the function and hands its result back to the caller. The expression reads card.
  202. func _valid_card(card: Variant) -> bool:Defines valid card, a reusable set of instructions. Parameters between the parentheses receive inputs. A return type after the arrow tells you which kind of result to expect.
  203. if not card is Dictionary:Checks not card is Dictionary. The indented instructions below run only if this test passes.
  204. return falseFinishes the function and hands its result back to the caller. The expression uses the yes-or-no value false.
  205. for key in ["title", "width", "height", "source", "direction", "mirrors", "splitters", "targets", "walls"]:Repeats the indented instructions for each value in ["title", "width", "height", "source", "direction", "mirrors", "splitters", "targets", "walls"].
  206. if not card.has(key):Checks not card.has(key). The indented instructions below run only if this test passes.
  207. return falseFinishes the function and hands its result back to the caller. The expression uses the yes-or-no value false.
  208. if not card.title is String or card.width != 6 or card.height != 4:Checks not card.title is String or card.width != 6 or card.height != 4. The indented instructions below run only if this test passes.
  209. return falseFinishes the function and hands its result back to the caller. The expression uses the yes-or-no value false.
  210. if not card.mirrors is Dictionary or not card.splitters is Dictionary:Checks not card.mirrors is Dictionary or not card.splitters is Dictionary. The indented instructions below run only if this test passes.
  211. return falseFinishes the function and hands its result back to the caller. The expression uses the yes-or-no value false.
  212. if not card.targets is Array or not card.walls is Array or card.targets.is_empty():Checks not card.targets is Array or not card.walls is Array or card.targets.is_empty(). The indented instructions below run only if this test passes.
  213. return falseFinishes the function and hands its result back to the caller. The expression uses the yes-or-no value false.
  214. if not _whole_in(card.source, 24) or not _whole_in(card.direction, 4):Checks not _whole_in(card.source, 24) or not _whole_in(card.direction, 4). The indented instructions below run only if this test passes.
  215. return falseFinishes the function and hands its result back to the caller. The expression uses the yes-or-no value false.
  216. for key in card.mirrors.keys() + card.splitters.keys():Repeats the indented instructions for each value in card.mirrors.keys() + card.splitters.keys().
  217. if not str(key).is_valid_int() or not _whole_in(int(key), 24):Checks not str(key).is_valid_int() or not _whole_in(int(key), 24). The indented instructions below run only if this test passes.
  218. return falseFinishes the function and hands its result back to the caller. The expression uses the yes-or-no value false.
  219. for value in card.mirrors.values() + card.splitters.values():Repeats the indented instructions for each value in card.mirrors.values() + card.splitters.values().
  220. if not _whole_in(value, 2):Checks not _whole_in(value, 2). The indented instructions below run only if this test passes.
  221. return falseFinishes the function and hands its result back to the caller. The expression uses the yes-or-no value false.
  222. for tile in card.targets + card.walls:Repeats the indented instructions for each value in card.targets + card.walls.
  223. if not _whole_in(tile, 24):Checks not _whole_in(tile, 24). The indented instructions below run only if this test passes.
  224. return falseFinishes the function and hands its result back to the caller. The expression uses the yes-or-no value false.
  225. return trueFinishes the function and hands its result back to the caller. The expression uses the yes-or-no value true.
  226. func _whole_in(value: Variant, limit: int) -> bool:Defines whole in, a reusable set of instructions. Parameters between the parentheses receive inputs. A return type after the arrow tells you which kind of result to expect.
  227. if not (value is int or value is float):Checks not (value is int or value is float). The indented instructions below run only if this test passes.
  228. return falseFinishes the function and hands its result back to the caller. The expression uses the yes-or-no value false.
  229. return float(value) == floorf(float(value)) and value >= 0 and value < limitFinishes the function and hands its result back to the caller. The expression converts a suitable value to a number that can include a fractional part.
  230. func _choose_card(index: int) -> void:Defines choose card, a reusable set of instructions. Parameters between the parentheses receive inputs. A return type after the arrow tells you which kind of result to expect.
  231. _load_level(cards[index])Calls _load_level with the values in its parentheses.
  232. func _undo_turn() -> void:Defines undo turn, a reusable set of instructions. Parameters between the parentheses receive inputs. A return type after the arrow tells you which kind of result to expect.
  233. if history.is_empty():Checks history.is_empty(). The indented instructions below run only if this test passes.
  234. returnFinishes the function right here. Any later instructions in this function are skipped.
  235. turns = history.pop_back()Stores the new value in turns. The expression takes the final item out of the list and returns it.
  236. _refresh()Calls _refresh with the values in its parentheses.
  237. func _restart_room() -> void:Defines restart room, a reusable set of instructions. Parameters between the parentheses receive inputs. A return type after the arrow tells you which kind of result to expect.
  238. _load_level(level)Calls _load_level with the values in its parentheses.
  239. func _key(state: Dictionary, knobs: Array) -> String:Defines key, a reusable set of instructions. Parameters between the parentheses receive inputs. A return type after the arrow tells you which kind of result to expect.
  240. var key := ""Creates a variable named key. The expression uses the text inside the quotes. Godot infers the type from the first value.
  241. for tile in knobs:Repeats the indented instructions for each value in knobs.
  242. key += str(_orientation(tile, state))Reads key, adds to its old value, then stores the result back in the same place.
  243. return keyFinishes the function and hands its result back to the caller. The expression reads key.
  244. func _best_next_turn() -> int:Defines best next turn, a reusable set of instructions. Parameters between the parentheses receive inputs. A return type after the arrow tells you which kind of result to expect.
  245. if beam.lit.size() == level.targets.size():Checks beam.lit.size() == level.targets.size(). The indented instructions below run only if this test passes.
  246. return -2Finishes the function and hands its result back to the caller. The expression reads -2.
  247. var knobs := tile_buttons.keys()Creates a variable named knobs. The expression calls tile_buttons.keys with the values in its parentheses. Godot infers the type from the first value.
  248. if knobs.size() > 8:Checks knobs.size() > 8. The indented instructions below run only if this test passes.
  249. return -1Finishes the function and hands its result back to the caller. The expression reads -1.
  250. var queue: Array[Dictionary] = [{"turns": turns.duplicate(), "first": -1}]Creates a variable named queue. The expression makes a list whose items keep their order. The type after the colon says what kind of value it can hold.
  251. var visited: Dictionary = {_key(turns, knobs): true}Creates a variable named visited. The expression makes a dictionary that looks up values by key. The type after the colon says what kind of value it can hold.
  252. while not queue.is_empty():Keeps repeating while not queue.is_empty() stays true. The loop body should eventually change the result or leave with break.
  253. var candidate: Dictionary = queue.pop_front()Creates a variable named candidate. The expression takes the first item out of the list and returns it. The type after the colon says what kind of value it can hold.
  254. var state: Dictionary = candidate.turnsCreates a variable named state. The expression reads candidate.turns. The type after the colon says what kind of value it can hold.
  255. if _trace(state).lit.size() == level.targets.size():Checks _trace(state).lit.size() == level.targets.size(). The indented instructions below run only if this test passes.
  256. return int(candidate.first)Finishes the function and hands its result back to the caller. The expression converts a suitable value to a whole number.
  257. for tile in knobs:Repeats the indented instructions for each value in knobs.
  258. var neighbour := state.duplicate()Creates a variable named neighbour. The expression copies the collection so a later change can leave the original alone. Godot infers the type from the first value.
  259. neighbour[tile] = 1 - _orientation(tile, state)Stores the new value in neighbour[tile]. The expression calculates a new value from the expressions on either side of the operator.
  260. var key := _key(neighbour, knobs)Creates a variable named key. The expression calls _key with the values in its parentheses. Godot infers the type from the first value.
  261. if visited.has(key):Checks visited.has(key). The indented instructions below run only if this test passes.
  262. continueSkips the rest of this turn through the loop and moves on to the next item.
  263. visited[key] = trueStores the new value in visited[key]. The expression uses the yes-or-no value true.
  264. var first := int(candidate.first) if candidate.first >= 0 else int(tile)Creates a variable named first. The expression converts a suitable value to a whole number. Godot infers the type from the first value.
  265. queue.append({"turns": neighbour, "first": first})Adds an item to the end of a list.
  266. return -1Finishes the function and hands its result back to the caller. The expression reads -1.
  267. func _hint() -> void:Defines hint, a reusable set of instructions. Parameters between the parentheses receive inputs. A return type after the arrow tells you which kind of result to expect.
  268. var tile := _best_next_turn()Creates a variable named tile. The expression calls _best_next_turn with the values in its parentheses. Godot infers the type from the first value.
  269. if tile == -2:Checks tile == -2. The indented instructions below run only if this test passes.
  270. status.text = "The exhibits are already awake."Updates status.text, which controls the words a player sees. The expression uses the text inside the quotes.
  271. returnFinishes the function right here. Any later instructions in this function are skipped.
  272. if tile < 0:Checks tile < 0. The indented instructions below run only if this test passes.
  273. status.text = "No hint available for this layout."Updates status.text, which controls the words a player sees. The expression uses the text inside the quotes.
  274. returnFinishes the function right here. Any later instructions in this function are skipped.
  275. var row := floori(float(tile) / int(level.width)) + 1Creates a variable named row. The expression calls floori with the values in its parentheses. Godot infers the type from the first value.
  276. var col := tile % int(level.width) + 1Creates a variable named col. The expression calculates a new value from the expressions on either side of the operator. Godot infers the type from the first value.
  277. status.text = "Try row %d, column %d. This keeps you on a shortest route." % [row, col]Updates status.text, which controls the words a player sees. The expression uses the text inside the quotes.
  278. func _flash_beam() -> void:Defines flash beam, a reusable set of instructions. Parameters between the parentheses receive inputs. A return type after the arrow tells you which kind of result to expect.
  279. if glow_tween != null and glow_tween.is_valid():Checks glow_tween != null and glow_tween.is_valid(). The indented instructions below run only if this test passes.
  280. glow_tween.kill()Calls glow_tween.kill with the values in its parentheses.
  281. beam_brightness = 0.0Stores the new value in beam_brightness. The expression reads 0.0.
  282. glow_tween = create_tween()Stores the new value in glow_tween. The expression creates an animation that changes a value smoothly over time.
  283. glow_tween.tween_property(self, "beam_brightness", 1.0, 0.32)Animates one property toward a target value over the given number of seconds.

gallery.json holds data for the game. Curly braces group named values, square brackets make ordered lists and each colon connects a key to its value.

Find and fix a bug

If the beam never appears after a tap, check that tween_property targets the exact name beam_brightness and that its setter queues a redraw.

Try a change

Guided: compare two fade speeds. Stretch: add a Reduce motion choice that sets full brightness immediately while leaving the logic identical.