How the finished Cabin Crew Express game works

Download the game source

Follow a service turn

  1. Receive an action. Read a movement button, a galley selection or a passenger seat.
  2. Check the rules. Confirm the row, cart capacity, requested item and any priority requirements.
  3. Update the mission. Move Ari or fill or use a cart slot. A successful service marks the seat as done and spends a turn.
  4. Refresh the cabin. Draw the new state and tell the player what changed. Completing a flight saves medals and unlocks on the device.

A hint can test possible actions with the same rules before asking the player to make a move.

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 scripts/cabin.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 Rules = preload("res://scripts/service_rules.gd")Creates a constant named Rules. The expression prepares a resource at a fixed project path when the script is loaded.
  3. const Catalog = preload("res://scripts/flight_catalog.gd")Creates a constant named Catalog. The expression prepares a resource at a fixed project path when the script is loaded.
  4. const Progress = preload("res://scripts/progress.gd")Creates a constant named Progress. The expression prepares a resource at a fixed project path when the script is loaded.
  5. const CabinBoard = preload("res://scripts/cabin_board.gd")Creates a constant named CabinBoard. The expression prepares a resource at a fixed project path when the script is loaded.
  6. const VIEW := Vector2(1280, 720)Creates a constant named VIEW. The expression packs x and y into one value. Godot infers the type from the first value.
  7. const INK := Color("#162a45")Creates a constant named INK. The expression builds a colour from these values. Godot infers the type from the first value.
  8. const WHITE := Color("#f9f1df")Creates a constant named WHITE. The expression builds a colour from these values. Godot infers the type from the first value.
  9. const MINT := Color("#a0e6de")Creates a constant named MINT. The expression builds a colour from these values. Godot infers the type from the first value.
  10. const GOLD := Color("#ffd69d")Creates a constant named GOLD. The expression builds a colour from these values. Godot infers the type from the first value.
  11. const MUTED := Color("#aec5d2")Creates a constant named MUTED. The expression builds a colour from these values. Godot infers the type from the first value.
  12. const EDGE := Color("#7092a5")Creates a constant named EDGE. The expression builds a colour from these values. Godot infers the type from the first value.
  13. const ITEM_INK := [Color("#80dbe7"), Color("#ffd39e"), Color("#ccb7f2")]Creates a constant named ITEM_INK. The expression makes a list whose items keep their order. Godot infers the type from the first value.
  14. const SEATS := ["A", "B", "C", "D"]Creates a constant named SEATS. The expression makes a list whose items keep their order. Godot infers the type from the first value.
  15. var levels: Array[Dictionary] = []Creates a variable named levels. The expression makes a list whose items keep their order. The type after the colon says what kind of value it can hold.
  16. var current_index := 0Creates a variable named current_index. The expression uses the whole number 0. Godot infers the type from the first value.
  17. var level := {}Creates a variable named level. The expression makes a dictionary that looks up values by key. Godot infers the type from the first value.
  18. var state := {}Creates a variable named state. The expression makes a dictionary that looks up values by key. Godot infers the type from the first value.
  19. var medals := {}Creates a variable named medals. The expression makes a dictionary that looks up values by key. Godot infers the type from the first value.
  20. var hint := -1Creates a variable named hint. The expression reads -1. Godot infers the type from the first value.
  21. var backdrops: Dictionary = {}Creates a variable named backdrops. The expression makes a dictionary that looks up values by key. The type after the colon says what kind of value it can hold.
  22. var background: TextureRectDeclares background for later use. A colon followed by a type says which kind of value belongs here.
  23. var board: ControlDeclares board for later use. A colon followed by a type says which kind of value belongs here.
  24. var flight_number: LabelDeclares flight_number for later use. A colon followed by a type says which kind of value belongs here.
  25. var title: LabelDeclares title for later use. A colon followed by a type says which kind of value belongs here.
  26. var mission: LabelDeclares mission for later use. A colon followed by a type says which kind of value belongs here.
  27. var count: LabelDeclares count for later use. A colon followed by a type says which kind of value belongs here.
  28. var turns: LabelDeclares turns for later use. A colon followed by a type says which kind of value belongs here.
  29. var cart: LabelDeclares cart for later use. A colon followed by a type says which kind of value belongs here.
  30. var status: LabelDeclares status for later use. A colon followed by a type says which kind of value belongs here.
  31. var member: LabelDeclares member for later use. A colon followed by a type says which kind of value belongs here.
  32. var next_button: ButtonDeclares next_button for later use. A colon followed by a type says which kind of value belongs here.
  33. var overlay: ControlDeclares overlay for later use. A colon followed by a type says which kind of value belongs here.
  34. var overlay_title: LabelDeclares overlay_title for later use. A colon followed by a type says which kind of value belongs here.
  35. var overlay_text: LabelDeclares overlay_text for later use. A colon followed by a type says which kind of value belongs here.
  36. var overlay_buttons: Array[Button] = []Creates a variable named overlay_buttons. The expression makes a list whose items keep their order. The type after the colon says what kind of value it can hold.
  37. var overlay_close: ButtonDeclares overlay_close for later use. A colon followed by a type says which kind of value belongs here.
  38. var gameplay_buttons: Array[Button] = []Creates a variable named gameplay_buttons. The expression makes a list whose items keep their order. The type after the colon says what kind of value it can hold.
  39. var focused_before: ControlDeclares focused_before for later use. A colon followed by a type says which kind of value belongs here.
  40. 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.
  41. levels = Catalog.read()Stores the new value in levels. The expression calls Catalog.read with the values in its parentheses.
  42. medals = Progress.read()["medals"]Stores the new value in medals. The expression calls Progress.read with the values in its parentheses.
  43. for name in ["cabin", "galley"]:Repeats the indented instructions for each value in ["cabin", "galley"].
  44. var path := "res://art/%s.jpg" % nameCreates a variable named path. The expression uses the text inside the quotes. Godot infers the type from the first value.
  45. if ResourceLoader.exists(path):Checks ResourceLoader.exists(path). The indented instructions below run only if this test passes.
  46. backdrops[name] = load(path)Stores the new value in backdrops[name]. The expression reads a resource from the project when this instruction runs.
  47. _build_interface()Calls _build_interface with the values in its parentheses.
  48. if levels.is_empty():Checks levels.is_empty(). The indented instructions below run only if this test passes.
  49. status.text = "Flight plans could not be loaded. Open the complete project folder."Updates status.text, which controls the words a player sees. The expression uses the text inside the quotes.
  50. for button in gameplay_buttons:Repeats the indented instructions for each value in gameplay_buttons.
  51. button.disabled = trueUpdates button.disabled, which controls whether the control should ignore activation. The expression uses the yes-or-no value true.
  52. returnFinishes the function right here. Any later instructions in this function are skipped.
  53. _open_flight(mini(_unlocked(), levels.size() - 1))Calls _open_flight with the values in its parentheses.
  54. gameplay_buttons[Rules.FORWARD].grab_focus()Continues this part of the script. Read the expression on this line in the context of the nearby declaration or function.
  55. func _style(fill: Color, edge: Color, radius: int = 12, border: int = 1) -> StyleBoxFlat:Defines style, 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.
  56. var box := StyleBoxFlat.new()Creates a variable named box. The expression creates a new StyleBoxFlat object. Godot infers the type from the first value.
  57. box.bg_color = fillStores the new value in box.bg_color. The expression reads fill.
  58. box.border_color = edgeStores the new value in box.border_color. The expression reads edge.
  59. box.set_border_width_all(border)Calls box.set_border_width_all with the values in its parentheses.
  60. box.set_corner_radius_all(radius)Calls box.set_corner_radius_all with the values in its parentheses.
  61. return boxFinishes the function and hands its result back to the caller. The expression reads box.
  62. func _panel(frame: Rect2, parent: Control, fill: Color, edge: Color = EDGE, radius: int = 14) -> Panel:Defines panel, 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.
  63. var panel := Panel.new()Creates a variable named panel. The expression creates a new Panel object. Godot infers the type from the first value.
  64. panel.position = frame.positionUpdates panel.position, which controls the node's local x and y location. The expression reads frame.position.
  65. panel.size = frame.sizeUpdates panel.size, which controls the control's width and height. The expression reads frame.size.
  66. panel.mouse_filter = Control.MOUSE_FILTER_IGNOREUpdates panel.mouse_filter, which controls how this control participates in pointer and touch input. The expression reads Control.MOUSE_FILTER_IGNORE.
  67. panel.add_theme_stylebox_override("panel", _style(fill, edge, radius))Calls panel.add_theme_stylebox_override with the values in its parentheses.
  68. parent.add_child(panel)Adds the new node to the scene tree so that Godot can run and draw it.
  69. return panelFinishes the function and hands its result back to the caller. The expression reads panel.
  70. func _label(value: String, frame: Rect2, font_size: int, parent: Control, ink: Color = WHITE, wrap: bool = false) -> Label:Defines 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.
  71. var label := Label.new()Creates a variable named label. The expression creates a new Label object. Godot infers the type from the first value.
  72. label.position = frame.positionUpdates label.position, which controls the node's local x and y location. The expression reads frame.position.
  73. label.size = frame.sizeUpdates label.size, which controls the control's width and height. The expression reads frame.size.
  74. label.text = valueUpdates label.text, which controls the words a player sees. The expression reads value.
  75. label.vertical_alignment = VERTICAL_ALIGNMENT_CENTERStores the new value in label.vertical_alignment. The expression reads VERTICAL_ALIGNMENT_CENTER.
  76. label.mouse_filter = Control.MOUSE_FILTER_IGNOREUpdates label.mouse_filter, which controls how this control participates in pointer and touch input. The expression reads Control.MOUSE_FILTER_IGNORE.
  77. label.add_theme_font_size_override("font_size", font_size)Calls label.add_theme_font_size_override with the values in its parentheses.
  78. label.add_theme_color_override("font_color", ink)Calls label.add_theme_color_override with the values in its parentheses.
  79. if wrap:Checks wrap. The indented instructions below run only if this test passes.
  80. label.autowrap_mode = TextServer.AUTOWRAP_WORD_SMARTStores the new value in label.autowrap_mode. The expression reads TextServer.AUTOWRAP_WORD_SMART.
  81. parent.add_child(label)Adds the new node to the scene tree so that Godot can run and draw it.
  82. return labelFinishes the function and hands its result back to the caller. The expression reads label.
  83. func _button(value: String, frame: Rect2, parent: Control, callback: Callable, font_size: int = 16) -> Button:Defines button, 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.
  84. var button := Button.new()Creates a variable named button. The expression creates a new Button object. Godot infers the type from the first value.
  85. button.position = frame.positionUpdates button.position, which controls the node's local x and y location. The expression reads frame.position.
  86. button.size = frame.sizeUpdates button.size, which controls the control's width and height. The expression reads frame.size.
  87. button.text = valueUpdates button.text, which controls the words a player sees. The expression reads value.
  88. button.add_theme_font_size_override("font_size", font_size)Calls button.add_theme_font_size_override with the values in its parentheses.
  89. button.add_theme_color_override("font_color", WHITE)Calls button.add_theme_color_override with the values in its parentheses.
  90. button.add_theme_color_override("font_hover_color", WHITE)Calls button.add_theme_color_override with the values in its parentheses.
  91. button.add_theme_color_override("font_pressed_color", INK)Calls button.add_theme_color_override with the values in its parentheses.
  92. button.add_theme_color_override("font_disabled_color", MUTED.darkened(0.32))Calls button.add_theme_color_override with the values in its parentheses.
  93. button.add_theme_stylebox_override("normal", _style(Color("#274765"), Color("#64859b")))Calls button.add_theme_stylebox_override with the values in its parentheses.
  94. button.add_theme_stylebox_override("hover", _style(Color("#375c7c"), MINT))Calls button.add_theme_stylebox_override with the values in its parentheses.
  95. button.add_theme_stylebox_override("pressed", _style(MINT, WHITE))Calls button.add_theme_stylebox_override with the values in its parentheses.
  96. button.add_theme_stylebox_override("focus", _style(Color(0, 0, 0, 0), GOLD, 12, 2))Calls button.add_theme_stylebox_override with the values in its parentheses.
  97. button.add_theme_stylebox_override("disabled", _style(Color("#1b304a"), Color("#324a61")))Calls button.add_theme_stylebox_override with the values in its parentheses.
  98. button.pressed.connect(callback)Links a signal to the function that should run when the event happens.
  99. parent.add_child(button)Adds the new node to the scene tree so that Godot can run and draw it.
  100. return buttonFinishes the function and hands its result back to the caller. The expression reads button.
  101. func _build_interface() -> void:Defines build interface, 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.
  102. var backdrop := ColorRect.new()Creates a variable named backdrop. The expression creates a new ColorRect object. Godot infers the type from the first value.
  103. backdrop.size = VIEWUpdates backdrop.size, which controls the control's width and height. The expression reads VIEW.
  104. backdrop.color = Color("#23364f")Stores the new value in backdrop.color. The expression builds a colour from these values.
  105. backdrop.mouse_filter = Control.MOUSE_FILTER_IGNOREUpdates backdrop.mouse_filter, which controls how this control participates in pointer and touch input. The expression reads Control.MOUSE_FILTER_IGNORE.
  106. add_child(backdrop)Adds the new node to the scene tree so that Godot can run and draw it.
  107. background = TextureRect.new()Stores the new value in background. The expression creates a new TextureRect object.
  108. background.size = VIEWUpdates background.size, which controls the control's width and height. The expression reads VIEW.
  109. background.expand_mode = TextureRect.EXPAND_IGNORE_SIZEStores the new value in background.expand_mode. The expression reads TextureRect.EXPAND_IGNORE_SIZE.
  110. background.stretch_mode = TextureRect.STRETCH_KEEP_ASPECT_COVEREDStores the new value in background.stretch_mode. The expression reads TextureRect.STRETCH_KEEP_ASPECT_COVERED.
  111. background.mouse_filter = Control.MOUSE_FILTER_IGNOREUpdates background.mouse_filter, which controls how this control participates in pointer and touch input. The expression reads Control.MOUSE_FILTER_IGNORE.
  112. add_child(background)Adds the new node to the scene tree so that Godot can run and draw it.
  113. var tint := ColorRect.new()Creates a variable named tint. The expression creates a new ColorRect object. Godot infers the type from the first value.
  114. tint.size = VIEWUpdates tint.size, which controls the control's width and height. The expression reads VIEW.
  115. tint.color = Color(0.02, 0.04, 0.10, 0.39)Stores the new value in tint.color. The expression builds a colour from these values.
  116. tint.mouse_filter = Control.MOUSE_FILTER_IGNOREUpdates tint.mouse_filter, which controls how this control participates in pointer and touch input. The expression reads Control.MOUSE_FILTER_IGNORE.
  117. add_child(tint)Adds the new node to the scene tree so that Godot can run and draw it.
  118. _panel(Rect2(22, 18, 1236, 91), self, Color(0.06, 0.13, 0.22, 0.97), EDGE, 18)Calls _panel with the values in its parentheses.
  119. _label("CABIN CREW EXPRESS", Rect2(48, 32, 720, 53), 43, self)Calls _label with the values in its parentheses.
  120. flight_number = _label("", Rect2(840, 25, 385, 28), 20, self, MINT)Stores the new value in flight_number. The expression calls _label with the values in its parentheses.
  121. flight_number.horizontal_alignment = HORIZONTAL_ALIGNMENT_RIGHTStores the new value in flight_number.horizontal_alignment. The expression reads HORIZONTAL_ALIGNMENT_RIGHT.
  122. title = _label("", Rect2(800, 51, 425, 39), 29, self)Stores the new value in title. The expression calls _label with the values in its parentheses.
  123. title.horizontal_alignment = HORIZONTAL_ALIGNMENT_RIGHTStores the new value in title.horizontal_alignment. The expression reads HORIZONTAL_ALIGNMENT_RIGHT.
  124. board = CabinBoard.new()Stores the new value in board. The expression creates a new CabinBoard object.
  125. board.position = Vector2(22, 125)Updates board.position, which controls the node's local x and y location. The expression packs x and y into one value.
  126. board.size = Vector2(626, 506)Updates board.size, which controls the control's width and height. The expression packs x and y into one value.
  127. board.action_selected.connect(_take_action)Links a signal to the function that should run when the event happens.
  128. add_child(board)Adds the new node to the scene tree so that Godot can run and draw it.
  129. _panel(Rect2(660, 125, 598, 506), self, Color(0.071, 0.15, 0.25, 0.98), EDGE, 21)Calls _panel with the values in its parentheses.
  130. _label("FLIGHT BRIEF", Rect2(681, 138, 450, 23), 15, self, GOLD)Calls _label with the values in its parentheses.
  131. mission = _label("", Rect2(681, 168, 550, 61), 20, self, WHITE, true)Stores the new value in mission. The expression calls _label with the values in its parentheses.
  132. count = _label("", Rect2(681, 236, 300, 28), 21, self, MINT)Stores the new value in count. The expression calls _label with the values in its parentheses.
  133. turns = _label("", Rect2(986, 236, 246, 28), 18, self, MUTED)Stores the new value in turns. The expression calls _label with the values in its parentheses.
  134. turns.horizontal_alignment = HORIZONTAL_ALIGNMENT_RIGHTStores the new value in turns.horizontal_alignment. The expression reads HORIZONTAL_ALIGNMENT_RIGHT.
  135. _panel(Rect2(679, 275, 560, 63), self, Color("#223f59"), Color("#53758a"), 12)Calls _panel with the values in its parentheses.
  136. cart = _label("", Rect2(695, 282, 529, 47), 19, self, WHITE)Stores the new value in cart. The expression calls _label with the values in its parentheses.
  137. member = _label("", Rect2(681, 343, 320, 26), 16, self, GOLD)Stores the new value in member. The expression calls _label with the values in its parentheses.
  138. _label("MOVE", Rect2(1111, 343, 120, 25), 15, self, MUTED).horizontal_alignment = HORIZONTAL_ALIGNMENT_RIGHTCalls _label with the values in its parentheses.
  139. gameplay_buttons.resize(Rules.ACTION_COUNT)Calls gameplay_buttons.resize with the values in its parentheses.
  140. gameplay_buttons[Rules.BACK] = _button("↑ Toward galley", Rect2(680, 373, 269, 50), self, _take_action.bind(Rules.BACK), 17)Stores the new value in gameplay_buttons[Rules.BACK]. The expression calls _button with the values in its parentheses.
  141. gameplay_buttons[Rules.FORWARD] = _button("↓ Down aisle", Rect2(963, 373, 276, 50), self, _take_action.bind(Rules.FORWARD), 17)Stores the new value in gameplay_buttons[Rules.FORWARD]. The expression calls _button with the values in its parentheses.
  142. for item in range(Rules.ITEMS.size()):Repeats the indented instructions for each value in range(Rules.ITEMS.size()).
  143. var x := 680 + item * 185Creates a variable named x. The expression calculates a new value from the expressions on either side of the operator. Godot infers the type from the first value.
  144. var stock := _button("+ " + Rules.ITEMS[item], Rect2(x, 431, 133, 49), self, _take_action.bind(Rules.STOCK + item), 17)Creates a variable named stock. The expression calls _button with the values in its parentheses. Godot infers the type from the first value.
  145. stock.add_theme_color_override("font_color", ITEM_INK[item])Calls stock.add_theme_color_override with the values in its parentheses.
  146. gameplay_buttons[Rules.STOCK + item] = stockContinues this part of the script. Read the expression on this line in the context of the nearby declaration or function.
  147. var unload := _button("−", Rect2(x + 137, 431, 43, 49), self, _take_action.bind(Rules.DISCARD + item), 20)Creates a variable named unload. The expression calls _button with the values in its parentheses. Godot infers the type from the first value.
  148. unload.tooltip_text = "Unload " + Rules.ITEMS[item].to_lower() + " at the galley"Stores the new value in unload.tooltip_text. The expression uses the text inside the quotes.
  149. gameplay_buttons[Rules.DISCARD + item] = unloadContinues this part of the script. Read the expression on this line in the context of the nearby declaration or function.
  150. for seat in range(SEATS.size()):Repeats the indented instructions for each value in range(SEATS.size()).
  151. gameplay_buttons[Rules.SERVE + seat] = _button("Serve " + SEATS[seat], Rect2(680 + seat * 141, 488, 134, 50), self, _take_action.bind(Rules.SERVE + seat), 17)Continues this part of the script. Read the expression on this line in the context of the nearby declaration or function.
  152. status = _label("", Rect2(681, 551, 550, 65), 18, self, MINT, true)Stores the new value in status. The expression calls _label with the values in its parentheses.
  153. status.vertical_alignment = VERTICAL_ALIGNMENT_TOPStores the new value in status.vertical_alignment. The expression reads VERTICAL_ALIGNMENT_TOP.
  154. _panel(Rect2(22, 645, 1236, 56), self, Color(0.06, 0.13, 0.22, 0.98), EDGE, 16)Calls _panel with the values in its parentheses.
  155. _button("Flights", Rect2(36, 652, 130, 42), self, _show_flights)Calls _button with the values in its parentheses.
  156. _button("How to play", Rect2(176, 652, 146, 42), self, _show_help)Calls _button with the values in its parentheses.
  157. _button("Route hint", Rect2(332, 652, 148, 42), self, _show_hint)Calls _button with the values in its parentheses.
  158. _button("Restart flight", Rect2(490, 652, 160, 42), self, _restart)Calls _button with the values in its parentheses.
  159. _label("Arrow keys to move · A–D to serve", Rect2(671, 653, 322, 40), 16, self, MUTED)Calls _label with the values in its parentheses.
  160. next_button = _button("Next flight →", Rect2(1005, 652, 239, 42), self, _continue)Stores the new value in next_button. The expression calls _button with the values in its parentheses.
  161. _build_overlay()Calls _build_overlay with the values in its parentheses.
  162. func _build_overlay() -> void:Defines build overlay, 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.
  163. overlay = Control.new()Stores the new value in overlay. The expression creates a new Control object.
  164. overlay.size = VIEWUpdates overlay.size, which controls the control's width and height. The expression reads VIEW.
  165. overlay.mouse_filter = Control.MOUSE_FILTER_STOPUpdates overlay.mouse_filter, which controls how this control participates in pointer and touch input. The expression reads Control.MOUSE_FILTER_STOP.
  166. add_child(overlay)Adds the new node to the scene tree so that Godot can run and draw it.
  167. var veil := ColorRect.new()Creates a variable named veil. The expression creates a new ColorRect object. Godot infers the type from the first value.
  168. veil.size = VIEWUpdates veil.size, which controls the control's width and height. The expression reads VIEW.
  169. veil.color = Color(0.012, 0.023, 0.047, 0.77)Stores the new value in veil.color. The expression builds a colour from these values.
  170. veil.mouse_filter = Control.MOUSE_FILTER_IGNOREUpdates veil.mouse_filter, which controls how this control participates in pointer and touch input. The expression reads Control.MOUSE_FILTER_IGNORE.
  171. overlay.add_child(veil)Adds the new node to the scene tree so that Godot can run and draw it.
  172. _panel(Rect2(206, 110, 868, 505), overlay, Color("#19344e"), EDGE, 20)Calls _panel with the values in its parentheses.
  173. overlay_title = _label("", Rect2(237, 138, 740, 55), 34, overlay)Stores the new value in overlay_title. The expression calls _label with the values in its parentheses.
  174. overlay_text = _label("", Rect2(237, 200, 800, 272), 22, overlay, WHITE, true)Stores the new value in overlay_text. The expression calls _label with the values in its parentheses.
  175. overlay_text.vertical_alignment = VERTICAL_ALIGNMENT_TOPStores the new value in overlay_text.vertical_alignment. The expression reads VERTICAL_ALIGNMENT_TOP.
  176. for index in range(9):Repeats the indented instructions for each value in range(9).
  177. var frame := Rect2(238 + (index % 3) * 270, 260 + floori(index / 3.0) * 72, 250, 60)Creates a variable named frame. The expression describes a position and a size. Godot infers the type from the first value.
  178. overlay_buttons.append(_button("", frame, overlay, _choose_flight.bind(index), 17))Adds an item to the end of a list.
  179. overlay_close = _button("Back to flight", Rect2(237, 534, 190, 47), overlay, _close_overlay, 18)Stores the new value in overlay_close. The expression calls _button with the values in its parentheses.
  180. overlay.hide()Makes this control invisible.
  181. func _unlocked() -> int:Defines unlocked, 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.
  182. var position := 0Creates a variable named position. The expression uses the whole number 0. Godot infers the type from the first value.
  183. while position < levels.size() and int(medals.get(position, 0)) > 0:Keeps repeating while position < levels.size() and int(medals.get(position, 0)) > 0 stays true. The loop body should eventually change the result or leave with break.
  184. position += 1Reads position, adds to its old value, then stores the result back in the same place.
  185. return positionFinishes the function and hands its result back to the caller. The expression reads position.
  186. func _show_help() -> void:Defines show help, 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.
  187. overlay_title.text = "How to serve the cabin"Updates overlay_title.text, which controls the words a player sees. The expression uses the text inside the quotes.
  188. overlay_text.text = "Stock water, a meal or a blanket at the galley. Your cart holds two items. Use the minus button to unload an item at the galley.\n\nMove to a row and select the matching seat. W means water, M means meal and B means blanket. Gold dots mark orders you must serve first.\n\nReturn to the galley when every request is served. Use Route hint if you get stuck. Rejected actions use no turns. On a keyboard, press 1–3 to stock and Shift+1–3 to unload."Updates overlay_text.text, which controls the words a player sees. The expression uses the text inside the quotes.
  189. for button in overlay_buttons:Repeats the indented instructions for each value in overlay_buttons.
  190. button.hide()Makes this control invisible.
  191. _show_overlay()Calls _show_overlay with the values in its parentheses.
  192. func _show_flights() -> void:Defines show flights, 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.
  193. overlay_title.text = "Choose a flight"Updates overlay_title.text, which controls the words a player sees. The expression uses the text inside the quotes.
  194. overlay_text.text = "Finish a flight to unlock the next. A gold mark means you reached its turn target."Updates overlay_text.text, which controls the words a player sees. The expression uses the text inside the quotes.
  195. for index in range(overlay_buttons.size()):Repeats the indented instructions for each value in range(overlay_buttons.size()).
  196. var button := overlay_buttons[index]Creates a variable named button. The expression looks up the item or key written between the square brackets. Godot infers the type from the first value.
  197. if index >= levels.size():Checks index >= levels.size(). The indented instructions below run only if this test passes.
  198. button.hide()Makes this control invisible.
  199. continueSkips the rest of this turn through the loop and moves on to the next item.
  200. var mark: int = medals.get(index, 0)Creates a variable named mark. 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.
  201. button.text = "%02d %s%s" % [index + 1, levels[index]["name"], " ★" if mark == 2 else " ✓" if mark == 1 else ""]Updates button.text, which controls the words a player sees. The expression chooses one of two values by checking the condition in the middle.
  202. button.disabled = index > _unlocked()Updates button.disabled, which controls whether the control should ignore activation. The expression reads index > _unlocked().
  203. button.show()Makes this control visible.
  204. _show_overlay()Calls _show_overlay with the values in its parentheses.
  205. func _show_overlay() -> void:Defines show overlay, 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.
  206. focused_before = get_viewport().gui_get_focus_owner()Stores the new value in focused_before. The expression calls get_viewport with the values in its parentheses.
  207. for child in get_children():Repeats the indented instructions for each value in get_children().
  208. if child is Button:Checks child is Button. The indented instructions below run only if this test passes.
  209. child.focus_mode = Control.FOCUS_NONEStores the new value in child.focus_mode. The expression reads Control.FOCUS_NONE.
  210. overlay.show()Makes this control visible.
  211. overlay_close.grab_focus()Gives this control keyboard focus so Space, Enter or arrow keys can reach it.
  212. func _close_overlay() -> void:Defines close overlay, 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.
  213. overlay.hide()Makes this control invisible.
  214. for child in get_children():Repeats the indented instructions for each value in get_children().
  215. if child is Button:Checks child is Button. The indented instructions below run only if this test passes.
  216. child.focus_mode = Control.FOCUS_ALLStores the new value in child.focus_mode. The expression reads Control.FOCUS_ALL.
  217. if is_instance_valid(focused_before):Checks is_instance_valid(focused_before). The indented instructions below run only if this test passes.
  218. focused_before.grab_focus()Gives this control keyboard focus so Space, Enter or arrow keys can reach it.
  219. func _choose_flight(index: int) -> void:Defines choose flight, 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.
  220. if index <= _unlocked():Checks index <= _unlocked(). The indented instructions below run only if this test passes.
  221. _close_overlay()Calls _close_overlay with the values in its parentheses.
  222. _open_flight(index)Calls _open_flight with the values in its parentheses.
  223. func _open_flight(index: int) -> void:Defines open flight, 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.
  224. current_index = clampi(index, 0, levels.size() - 1)Stores the new value in current_index. The expression keeps a whole number within the chosen bounds.
  225. level = levels[current_index]Stores the new value in level. The expression looks up the item or key written between the square brackets.
  226. state = Rules.initial_state()Stores the new value in state. The expression calls Rules.initial_state with the values in its parentheses.
  227. hint = -1Stores the new value in hint. The expression reads -1.
  228. background.texture = backdrops.get("galley", backdrops.get("cabin")) if level["group"] == "Meal Service" else backdrops.get("cabin")Stores the new value in background.texture. The expression looks up a named or indexed value, using a fallback when the call gives one.
  229. title.text = level["name"]Updates title.text, which controls the words a player sees. The expression looks up the item or key written between the square brackets.
  230. mission.text = level["brief"]Updates mission.text, which controls the words a player sees. The expression looks up the item or key written between the square brackets.
  231. flight_number.text = "%s · %02d / %02d" % [level["group"], current_index + 1, levels.size()]Updates flight_number.text, which controls the words a player sees. The expression uses the text inside the quotes.
  232. _refresh("Load the cart in the galley to begin.")Calls _refresh with the values in its parentheses.
  233. func _refresh(message: String) -> 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.
  234. var delivered := Rules.request_count(state, level)Creates a variable named delivered. The expression calls Rules.request_count with the values in its parentheses. Godot infers the type from the first value.
  235. count.text = "%d / %d requests served" % [delivered, level["orders"].size()]Updates count.text, which controls the words a player sees. The expression uses the text inside the quotes.
  236. turns.text = "Turns %d / target %d" % [state["turns"], level["par"]]Updates turns.text, which controls the words a player sees. The expression uses the text inside the quotes.
  237. var listed: Array[String] = []Creates a variable named listed. The expression makes a list whose items keep their order. The type after the colon says what kind of value it can hold.
  238. for item in range(Rules.ITEMS.size()):Repeats the indented instructions for each value in range(Rules.ITEMS.size()).
  239. for copy in range(state["bag"][item]):Repeats the indented instructions for each value in range(state["bag"][item]).
  240. listed.append(Rules.ITEMS[item])Adds an item to the end of a list.
  241. var n := listed.size()Creates a variable named n. The expression counts the items in this collection. Godot infers the type from the first value.
  242. cart.text = "Cart %d / %d %s" % [n, Rules.CART_CAPACITY, " + ".join(listed) if n > 0 else "Empty"]Updates cart.text, which controls the words a player sees. The expression chooses one of two values by checking the condition in the middle.
  243. member.text = "YOU ARE IN THE GALLEY" if state["row"] == 0 else "YOU ARE AT ROW %d" % state["row"]Updates member.text, which controls the words a player sees. The expression chooses one of two values by checking the condition in the middle.
  244. status.text = messageUpdates status.text, which controls the words a player sees. The expression reads message.
  245. var complete := Rules.is_complete(level, state)Creates a variable named complete. The expression calls Rules.is_complete with the values in its parentheses. Godot infers the type from the first value.
  246. next_button.disabled = not completeUpdates next_button.disabled, which controls whether the control should ignore activation. The expression reads not complete.
  247. next_button.text = "View flight results" if current_index == levels.size() - 1 else "Next flight →"Updates next_button.text, which controls the words a player sees. The expression chooses one of two values by checking the condition in the middle.
  248. for index in range(gameplay_buttons.size()):Repeats the indented instructions for each value in range(gameplay_buttons.size()).
  249. var button := gameplay_buttons[index]Creates a variable named button. The expression looks up the item or key written between the square brackets. Godot infers the type from the first value.
  250. button.disabled = completeUpdates button.disabled, which controls whether the control should ignore activation. The expression reads complete.
  251. button.modulate = GOLD if index == hint else WHITEUpdates button.modulate, which controls the colour and transparency used to tint this node and its children. The expression chooses one of two values by checking the condition in the middle.
  252. board.update_board(level, state, hint)Calls board.update_board with the values in its parentheses.
  253. func _take_action(action: int) -> void:Defines take action, 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.
  254. if level.is_empty() or overlay.visible or Rules.is_complete(level, state):Checks level.is_empty() or overlay.visible or Rules.is_complete(level, state). The indented instructions below run only if this test passes.
  255. returnFinishes the function right here. Any later instructions in this function are skipped.
  256. var result := Rules.next_state(level, state, action)Creates a variable named result. The expression calls Rules.next_state with the values in its parentheses. Godot infers the type from the first value.
  257. if result.is_empty():Checks result.is_empty(). The indented instructions below run only if this test passes.
  258. _refresh(Rules.denial(level, state, action))Calls _refresh with the values in its parentheses.
  259. returnFinishes the function right here. Any later instructions in this function are skipped.
  260. var served: bool = result["done"] != state["done"]Creates a variable named served. The expression evaluates the test to see whether it is true or false. The type after the colon says what kind of value it can hold.
  261. state = resultStores the new value in state. The expression reads result.
  262. hint = -1Stores the new value in hint. The expression reads -1.
  263. if Rules.is_complete(level, state):Checks Rules.is_complete(level, state). The indented instructions below run only if this test passes.
  264. var mark := 2 if int(state["turns"]) <= int(level["par"]) else 1Creates a variable named mark. The expression chooses one of two values by checking the condition in the middle. Godot infers the type from the first value.
  265. medals[current_index] = maxi(mark, int(medals.get(current_index, 0)))Stores the new value in medals[current_index]. The expression calls maxi with the values in its parentheses.
  266. var saved := Progress.write(medals) == OKCreates a variable named saved. The expression calls Progress.write with the values in its parentheses. Godot infers the type from the first value.
  267. var success := "Gold! Flight completed on target." if mark == 2 else "Flight completed."Creates a variable named success. The expression chooses one of two values by checking the condition in the middle. Godot infers the type from the first value.
  268. _refresh(success + ("" if saved else " Progress could not be saved."))Calls _refresh with the values in its parentheses.
  269. elif Rules.request_count(state, level) == level["orders"].size():If the earlier branches did not run, checks Rules.request_count(state, level) == level["orders"].size() next.
  270. _refresh("All passengers are served. Return to the galley.")Calls _refresh with the values in its parentheses.
  271. elif served:If the earlier branches did not run, checks served next.
  272. _refresh("Order delivered.")Calls _refresh with the values in its parentheses.
  273. elif action >= Rules.DISCARD:If the earlier branches did not run, checks action >= Rules.DISCARD next.
  274. _refresh("%s unloaded." % Rules.ITEMS[action - Rules.DISCARD])Calls _refresh with the values in its parentheses.
  275. elif action >= Rules.STOCK and action < Rules.SERVE:If the earlier branches did not run, checks action >= Rules.STOCK and action < Rules.SERVE next.
  276. _refresh("%s added to your cart." % Rules.ITEMS[action - Rules.STOCK])Calls _refresh with the values in its parentheses.
  277. else:Runs the indented fallback instructions if none of the earlier tests passed.
  278. _refresh("You are in the galley." if state["row"] == 0 else "Row %d. Choose a seat to serve." % state["row"])Calls _refresh with the values in its parentheses.
  279. func _show_hint() -> void:Defines show 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.
  280. if level.is_empty():Checks level.is_empty(). The indented instructions below run only if this test passes.
  281. returnFinishes the function right here. Any later instructions in this function are skipped.
  282. if Rules.is_complete(level, state):Checks Rules.is_complete(level, state). The indented instructions below run only if this test passes.
  283. _refresh("This flight is complete.")Calls _refresh with the values in its parentheses.
  284. returnFinishes the function right here. Any later instructions in this function are skipped.
  285. var route := Rules.shortest_route(level, state)Creates a variable named route. The expression calls Rules.shortest_route with the values in its parentheses. Godot infers the type from the first value.
  286. if route.is_empty():Checks route.is_empty(). The indented instructions below run only if this test passes.
  287. _refresh("Try restarting this flight to make a new plan.")Calls _refresh with the values in its parentheses.
  288. returnFinishes the function right here. Any later instructions in this function are skipped.
  289. hint = route[0]Stores the new value in hint. The expression looks up the item or key written between the square brackets.
  290. _refresh("Hint: %s. %d turns to finish by a shortest route." % [Rules.ACTION_NAMES[hint], route.size()])Calls _refresh with the values in its parentheses.
  291. func _restart() -> void:Defines restart, 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.
  292. if not level.is_empty():Checks not level.is_empty(). The indented instructions below run only if this test passes.
  293. _open_flight(current_index)Calls _open_flight with the values in its parentheses.
  294. func _continue() -> void:Defines continue, 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.
  295. if not Rules.is_complete(level, state):Checks not Rules.is_complete(level, state). The indented instructions below run only if this test passes.
  296. returnFinishes the function right here. Any later instructions in this function are skipped.
  297. if current_index < levels.size() - 1:Checks current_index < levels.size() - 1. The indented instructions below run only if this test passes.
  298. _open_flight(current_index + 1)Calls _open_flight with the values in its parentheses.
  299. else:Runs the indented fallback instructions if none of the earlier tests passed.
  300. _show_flights()Calls _show_flights with the values in its parentheses.
  301. func _input(event: InputEvent) -> void:Godot calls this when input arrives. The event tells the game which key, pointer or touch action happened.
  302. if not event is InputEventKey or not event.pressed or event.echo:Checks not event is InputEventKey or not event.pressed or event.echo. The indented instructions below run only if this test passes.
  303. returnFinishes the function right here. Any later instructions in this function are skipped.
  304. if event.keycode == KEY_ESCAPE and overlay.visible:Checks event.keycode == KEY_ESCAPE and overlay.visible. The indented instructions below run only if this test passes.
  305. _close_overlay()Calls _close_overlay with the values in its parentheses.
  306. get_viewport().set_input_as_handled()Calls get_viewport with the values in its parentheses.
  307. returnFinishes the function right here. Any later instructions in this function are skipped.
  308. if overlay.visible or level.is_empty():Checks overlay.visible or level.is_empty(). The indented instructions below run only if this test passes.
  309. returnFinishes the function right here. Any later instructions in this function are skipped.
  310. var action := -1Creates a variable named action. The expression reads -1. Godot infers the type from the first value.
  311. match event.keycode:Compares event.keycode to the patterns below and runs the first matching branch.
  312. KEY_DOWN:Starts the instructions for this branch. The indented lines belong together.
  313. action = Rules.FORWARDStores the new value in action. The expression reads Rules.FORWARD.
  314. KEY_UP:Starts the instructions for this branch. The indented lines belong together.
  315. action = Rules.BACKStores the new value in action. The expression reads Rules.BACK.
  316. KEY_A, KEY_B, KEY_C, KEY_D:Starts the instructions for this branch. The indented lines belong together.
  317. action = Rules.SERVE + event.keycode - KEY_AStores the new value in action. The expression calculates a new value from the expressions on either side of the operator.
  318. KEY_1, KEY_2, KEY_3:Starts the instructions for this branch. The indented lines belong together.
  319. action = (Rules.DISCARD if event.shift_pressed else Rules.STOCK) + event.keycode - KEY_1Stores the new value in action. The expression chooses one of two values by checking the condition in the middle.
  320. if action >= 0:Checks action >= 0. The indented instructions below run only if this test passes.
  321. _take_action(action)Calls _take_action with the values in its parentheses.
  322. get_viewport().set_input_as_handled()Calls get_viewport with the values in its parentheses.
Read scripts/cabin_board.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. signal action_selected(action: int)Defines an event this node can send. Listeners can connect functions to react when it happens.
  3. const Rules = preload("res://scripts/service_rules.gd")Creates a constant named Rules. The expression prepares a resource at a fixed project path when the script is loaded.
  4. const TEXT := Color("#f8f0dc")Creates a constant named TEXT. The expression builds a colour from these values. Godot infers the type from the first value.
  5. const SMOKE := Color("#a7c3d0")Creates a constant named SMOKE. The expression builds a colour from these values. Godot infers the type from the first value.
  6. const OUTLINE := Color("#5a768d")Creates a constant named OUTLINE. The expression builds a colour from these values. Godot infers the type from the first value.
  7. const MINT := Color("#a1ece3")Creates a constant named MINT. The expression builds a colour from these values. Godot infers the type from the first value.
  8. const GOLD := Color("#ffd69d")Creates a constant named GOLD. The expression builds a colour from these values. Godot infers the type from the first value.
  9. const ITEMS := [Color("#80dbe7"), Color("#ffd39e"), Color("#ccb7f2")]Creates a constant named ITEMS. The expression makes a list whose items keep their order. Godot infers the type from the first value.
  10. const ITEM_LETTERS := ["W", "M", "B"]Creates a constant named ITEM_LETTERS. The expression makes a list whose items keep their order. Godot infers the type from the first value.
  11. const SEATS := ["A", "B", "C", "D"]Creates a constant named SEATS. The expression makes a list whose items keep their order. Godot infers the type from the first value.
  12. const START_X := [48., 146., 390., 488.]Creates a constant named START_X. The expression makes a list whose items keep their order. Godot infers the type from the first value.
  13. const ROW_TOP := 88.0Creates a constant named ROW_TOP. The expression reads 88.0. Godot infers the type from the first value.
  14. const ROW_GAP := 54.0Creates a constant named ROW_GAP. The expression reads 54.0. Godot infers the type from the first value.
  15. const SEAT_SIZE := Vector2(84, 44)Creates a constant named SEAT_SIZE. The expression packs x and y into one value. Godot infers the type from the first value.
  16. const AISLE := Rect2(255, 88, 116, 368)Creates a constant named AISLE. The expression describes a position and a size. Godot infers the type from the first value.
  17. var level := {}Creates a variable named level. The expression makes a dictionary that looks up values by key. Godot infers the type from the first value.
  18. var state := {}Creates a variable named state. The expression makes a dictionary that looks up values by key. Godot infers the type from the first value.
  19. var hint := -1Creates a variable named hint. The expression reads -1. Godot infers the type from the first value.
  20. func update_board(next_level: Dictionary, next_state: Dictionary, next_hint: int) -> void:Defines update board, 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.
  21. level = next_levelStores the new value in level. The expression reads next_level.
  22. state = next_stateStores the new value in state. The expression reads next_state.
  23. hint = next_hintStores the new value in hint. The expression reads next_hint.
  24. queue_redraw()Asks Godot to call _draw again on a later frame so the screen matches the new state.
  25. func _text(value: String, centre: Vector2, font_size: int, ink: Color = TEXT) -> void:Defines text, 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.
  26. var font := ThemeDB.fallback_fontCreates a variable named font. The expression reads ThemeDB.fallback_font. Godot infers the type from the first value.
  27. var width := font.get_string_size(value, HORIZONTAL_ALIGNMENT_LEFT, -1, font_size).xCreates a variable named width. The expression calls font.get_string_size with the values in its parentheses. Godot infers the type from the first value.
  28. var y := centre.y + (font.get_ascent(font_size) - font.get_descent(font_size)) * 0.5Creates a variable named y. The expression calculates a new value from the expressions on either side of the operator. Godot infers the type from the first value.
  29. draw_string(font, Vector2(centre.x - width * 0.5, y), value, HORIZONTAL_ALIGNMENT_LEFT, -1, font_size, ink)Paints a piece of text with a font at a position measured from the node's origin.
  30. func _panel(rect: Rect2, fill: Color, border: Color, radius: int = 12) -> void:Defines panel, 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.
  31. var box := StyleBoxFlat.new()Creates a variable named box. The expression creates a new StyleBoxFlat object. Godot infers the type from the first value.
  32. box.bg_color = fillStores the new value in box.bg_color. The expression reads fill.
  33. box.border_color = borderStores the new value in box.border_color. The expression reads border.
  34. box.set_border_width_all(1)Calls box.set_border_width_all with the values in its parentheses.
  35. box.set_corner_radius_all(radius)Calls box.set_corner_radius_all with the values in its parentheses.
  36. draw_style_box(box, rect)Calls draw_style_box with the values in its parentheses.
  37. func _y_for(row: int) -> float:Defines y for, 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.
  38. return ROW_TOP + (row - 1) * ROW_GAPFinishes 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.
  39. func _draw() -> void:Godot calls this when the node needs drawing. The instructions inside paint the current state.
  40. if level.is_empty():Checks level.is_empty(). The indented instructions below run only if this test passes.
  41. returnFinishes the function right here. Any later instructions in this function are skipped.
  42. var rows: int = level["rows"]Creates a variable named rows. 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.
  43. _panel(Rect2(0, 0, size.x, size.y), Color(0.043, 0.09, 0.16, 0.94), OUTLINE, 22)Calls _panel with the values in its parentheses.
  44. _panel(Rect2(36, 22, 554, 42), Color("#324c62"), Color("#7d9caf"))Calls _panel with the values in its parentheses.
  45. _text("GALLEY", Vector2(313, 43), 20, TEXT)Calls _text with the values in its parentheses.
  46. for seat in range(SEATS.size()):Repeats the indented instructions for each value in range(SEATS.size()).
  47. _text(SEATS[seat], Vector2(START_X[seat] + SEAT_SIZE.x / 2., 76), 13, SMOKE)Calls _text with the values in its parentheses.
  48. _panel(Rect2(AISLE.position, Vector2(AISLE.size.x, (rows - 1) * ROW_GAP + 44)), Color("#213c56"), Color("#46667e"), 12)Calls _panel with the values in its parentheses.
  49. for row in range(1, rows + 1):Repeats the indented instructions for each value in range(1, rows + 1).
  50. var y := _y_for(row)Creates a variable named y. The expression calls _y_for with the values in its parentheses. Godot infers the type from the first value.
  51. for seat in range(SEATS.size()):Repeats the indented instructions for each value in range(SEATS.size()).
  52. var rect := Rect2(Vector2(START_X[seat], y), SEAT_SIZE)Creates a variable named rect. The expression describes a position and a size. Godot infers the type from the first value.
  53. _draw_seat(rect, row, seat)Calls _draw_seat with the values in its parentheses.
  54. var slot := Rect2(262, y + 1, 102, 42)Creates a variable named slot. The expression describes a position and a size. Godot infers the type from the first value.
  55. _panel(slot, Color("#375570"), MINT if row == state["row"] else Color("#698499"), 7)Calls _panel with the values in its parentheses.
  56. var label_position := slot.get_center()Creates a variable named label_position. The expression calls slot.get_center with the values in its parentheses. Godot infers the type from the first value.
  57. if row == state["row"]:Checks row == state["row"]. The indented instructions below run only if this test passes.
  58. label_position.x -= 23.0Reads label_position.x, subtracts from its old value, then stores the result back in the same place.
  59. _text(str(row), label_position, 21, TEXT)Calls _text with the values in its parentheses.
  60. _draw_cart()Calls _draw_cart with the values in its parentheses.
  61. _text("Gold dot: priority • W: water • M: meal • B: blanket", Vector2(313, size.y - 21), 15, SMOKE)Calls _text with the values in its parentheses.
  62. func _draw_seat(rect: Rect2, row: int, seat: int) -> void:Defines draw seat, 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.
  63. var index := Rules.order_at(level, row, seat)Creates a variable named index. The expression calls Rules.order_at with the values in its parentheses. Godot infers the type from the first value.
  64. var fill := Color("#162a40")Creates a variable named fill. The expression builds a colour from these values. Godot infers the type from the first value.
  65. var border := Color("#47647a")Creates a variable named border. The expression builds a colour from these values. Godot infers the type from the first value.
  66. var label: String = str(row) + SEATS[seat]Creates a variable named label. The expression turns a value into text for a player message. The type after the colon says what kind of value it can hold.
  67. var ink := SMOKECreates a variable named ink. The expression reads SMOKE. Godot infers the type from the first value.
  68. var priority := falseCreates a variable named priority. The expression uses the yes-or-no value false. Godot infers the type from the first value.
  69. if index >= 0:Checks index >= 0. The indented instructions below run only if this test passes.
  70. var order: Dictionary = level["orders"][index]Creates a variable named order. 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.
  71. priority = order["priority"] and not Rules.is_served(state, index)Stores the new value in priority. The expression evaluates the test to see whether it is true or false.
  72. if Rules.is_served(state, index):Checks Rules.is_served(state, index). The indented instructions below run only if this test passes.
  73. fill = Color("#23515a")Stores the new value in fill. The expression builds a colour from these values.
  74. label += " ✓"Reads label, adds to its old value, then stores the result back in the same place.
  75. ink = MINTStores the new value in ink. The expression reads MINT.
  76. else:Runs the indented fallback instructions if none of the earlier tests passed.
  77. fill = Color("#263c57")Stores the new value in fill. The expression builds a colour from these values.
  78. ink = ITEMS[order["item"]]Stores the new value in ink. The expression looks up the item or key written between the square brackets.
  79. label += " " + ITEM_LETTERS[order["item"]]Reads label, adds to its old value, then stores the result back in the same place.
  80. if priority or (hint == Rules.SERVE + seat and state["row"] == row):Checks priority or (hint == Rules.SERVE + seat and state["row"] == row). The indented instructions below run only if this test passes.
  81. border = GOLDStores the new value in border. The expression reads GOLD.
  82. _panel(rect, fill, border, 10)Calls _panel with the values in its parentheses.
  83. _text(label, rect.get_center(), 16, ink)Calls _text with the values in its parentheses.
  84. if priority:Checks priority. The indented instructions below run only if this test passes.
  85. draw_circle(rect.position + Vector2(9, 9), 3.7, GOLD, true, -1., true)Paints a filled circle or outline in this node's local coordinates.
  86. func _draw_cart() -> void:Defines draw cart, 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.
  87. var row: int = state["row"]Creates a variable named row. 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.
  88. var rect := Rect2(378, 31, 98, 25) if row == 0 else Rect2(315, _y_for(row) + 7, 44, 30)Creates a variable named rect. The expression describes a position and a size. Godot infers the type from the first value.
  89. _panel(rect, MINT, Color("#eefbf4"), 8)Calls _panel with the values in its parentheses.
  90. _text("CART" if row == 0 else "YOU", rect.get_center(), 11, Color("#172e49"))Calls _text with the values in its parentheses.
  91. func _gui_input(event: InputEvent) -> void:Godot calls this when the control receives an input event such as a tap.
  92. if level.is_empty() or Rules.is_complete(level, state):Checks level.is_empty() or Rules.is_complete(level, state). The indented instructions below run only if this test passes.
  93. returnFinishes the function right here. Any later instructions in this function are skipped.
  94. if not event is InputEventMouseButton or event.button_index != MOUSE_BUTTON_LEFT or not event.pressed:Checks not event is InputEventMouseButton or event.button_index != MOUSE_BUTTON_LEFT or not event.pressed. The indented instructions below run only if this test passes.
  95. returnFinishes the function right here. Any later instructions in this function are skipped.
  96. var point: Vector2 = event.positionCreates a variable named point. The expression reads event.position. The type after the colon says what kind of value it can hold.
  97. var row: int = state["row"]Creates a variable named row. 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.
  98. if Rect2(36, 22, 554, 42).has_point(point) and row == 1:Checks Rect2(36, 22, 554, 42).has_point(point) and row == 1. The indented instructions below run only if this test passes.
  99. action_selected.emit(Rules.BACK)Sends a signal to anything listening.
  100. accept_event()Calls accept_event with the values in its parentheses.
  101. returnFinishes the function right here. Any later instructions in this function are skipped.
  102. for target_row in range(1, level["rows"] + 1):Repeats the indented instructions for each value in range(1, level["rows"] + 1).
  103. var y := _y_for(target_row)Creates a variable named y. The expression calls _y_for with the values in its parentheses. Godot infers the type from the first value.
  104. if point.y < y or point.y > y + SEAT_SIZE.y:Checks point.y < y or point.y > y + SEAT_SIZE.y. The indented instructions below run only if this test passes.
  105. continueSkips the rest of this turn through the loop and moves on to the next item.
  106. if point.x >= 255 and point.x <= 371 and absi(row - target_row) == 1:Checks point.x >= 255 and point.x <= 371 and absi(row - target_row) == 1. The indented instructions below run only if this test passes.
  107. action_selected.emit(Rules.FORWARD if target_row > row else Rules.BACK)Sends a signal to anything listening.
  108. accept_event()Calls accept_event with the values in its parentheses.
  109. if row == target_row:Checks row == target_row. The indented instructions below run only if this test passes.
  110. for seat in range(SEATS.size()):Repeats the indented instructions for each value in range(SEATS.size()).
  111. if Rect2(Vector2(START_X[seat], y), SEAT_SIZE).has_point(point):Checks Rect2(Vector2(START_X[seat], y), SEAT_SIZE).has_point(point). The indented instructions below run only if this test passes.
  112. action_selected.emit(Rules.SERVE + seat)Sends a signal to anything listening.
  113. accept_event()Calls accept_event with the values in its parentheses.
  114. returnFinishes the function right here. Any later instructions in this function are skipped.
  115. returnFinishes the function right here. Any later instructions in this function are skipped.
Read scripts/flight_catalog.gd line by line
  1. extends RefCountedStarts with Godot's RefCounted type. This script gets the abilities of that type and adds the game's own rules.
  2. const CATALOG := "res://levels/flights.json"Creates a constant named CATALOG. The expression uses the text inside the quotes. Godot infers the type from the first value.
  3. static func read() -> Array[Dictionary]:Defines read, 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.
  4. var loaded: Variant = JSON.parse_string(FileAccess.get_file_as_string(CATALOG))Creates a variable named loaded. The expression tries to turn JSON text back into a value. The type after the colon says what kind of value it can hold.
  5. var flights: Array[Dictionary] = []Creates a variable named flights. The expression makes a list whose items keep their order. The type after the colon says what kind of value it can hold.
  6. if not loaded is Array:Checks not loaded is Array. The indented instructions below run only if this test passes.
  7. return flightsFinishes the function and hands its result back to the caller. The expression reads flights.
  8. for entry in loaded:Repeats the indented instructions for each value in loaded.
  9. if not entry is Dictionary:Checks not entry is Dictionary. The indented instructions below run only if this test passes.
  10. continueSkips the rest of this turn through the loop and moves on to the next item.
  11. var orders: Array[Dictionary] = []Creates a variable named orders. The expression makes a list whose items keep their order. The type after the colon says what kind of value it can hold.
  12. for item in entry.get("orders", []):Repeats the indented instructions for each value in entry.get("orders", []).
  13. orders.append({Adds an item to the end of a list.
  14. "row": int(item[0]), "seat": int(item[1]),Continues the same instruction on a new line. This is one of the arguments, data entries or expressions started above.
  15. "item": int(item[2]), "priority": bool(item[3]),Continues the same instruction on a new line. This is one of the arguments, data entries or expressions started above.
  16. })Continues the same instruction on a new line. This is one of the arguments, data entries or expressions started above.
  17. flights.append({Adds an item to the end of a list.
  18. "name": str(entry["name"]), "group": str(entry["group"]), "brief": str(entry["brief"]),Continues the same instruction on a new line. This is one of the arguments, data entries or expressions started above.
  19. "rows": int(entry["rows"]), "par": int(entry["par"]), "orders": orders,Continues the same instruction on a new line. This is one of the arguments, data entries or expressions started above.
  20. })Continues the same instruction on a new line. This is one of the arguments, data entries or expressions started above.
  21. return flightsFinishes the function and hands its result back to the caller. The expression reads flights.
Read scripts/progress.gd line by line
  1. extends RefCountedStarts with Godot's RefCounted type. This script gets the abilities of that type and adds the game's own rules.
  2. const SAVE := "user://cabin_progress.cfg"Creates a constant named SAVE. The expression uses the text inside the quotes. Godot infers the type from the first value.
  3. static func read(path: String = SAVE) -> Dictionary:Defines read, 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.
  4. var file := ConfigFile.new()Creates a variable named file. The expression creates a new ConfigFile object. Godot infers the type from the first value.
  5. if file.load(path) != OK:Checks file.load(path) != OK. The indented instructions below run only if this test passes.
  6. return {"medals": {}}Finishes the function and hands its result back to the caller. The expression makes a dictionary that looks up values by key.
  7. var medals: Variant = file.get_value("flights", "medals", {})Creates a variable named medals. The expression calls file.get_value with the values in its parentheses. The type after the colon says what kind of value it can hold.
  8. return {"medals": medals if medals is Dictionary else {}}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.
  9. static func write(medals: Dictionary, path: String = SAVE) -> Error:Defines write, 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.
  10. var file := ConfigFile.new()Creates a variable named file. The expression creates a new ConfigFile object. Godot infers the type from the first value.
  11. file.set_value("flights", "version", 1)Calls file.set_value with the values in its parentheses.
  12. file.set_value("flights", "medals", medals)Calls file.set_value with the values in its parentheses.
  13. return file.save(path)Finishes the function and hands its result back to the caller. The expression calls file.save with the values in its parentheses.
Read scripts/service_rules.gd line by line
  1. extends RefCountedStarts with Godot's RefCounted type. This script gets the abilities of that type and adds the game's own rules.
  2. ## Pure cabin rules used by the game screen, hint search and automated tests.A comment for the reader. Godot skips it when it runs the code.
  3. const ITEMS := ["Water", "Meal", "Blanket"]Creates a constant named ITEMS. The expression makes a list whose items keep their order. Godot infers the type from the first value.
  4. const FORWARD := 0Creates a constant named FORWARD. The expression uses the whole number 0. Godot infers the type from the first value.
  5. const BACK := 1Creates a constant named BACK. The expression uses the whole number 1. Godot infers the type from the first value.
  6. const STOCK := 2Creates a constant named STOCK. The expression uses the whole number 2. Godot infers the type from the first value.
  7. const SERVE := 5Creates a constant named SERVE. The expression uses the whole number 5. Godot infers the type from the first value.
  8. const DISCARD := 9Creates a constant named DISCARD. The expression uses the whole number 9. Godot infers the type from the first value.
  9. const ACTION_COUNT := 12Creates a constant named ACTION_COUNT. The expression uses the whole number 12. Godot infers the type from the first value.
  10. const CART_CAPACITY := 2Creates a constant named CART_CAPACITY. The expression uses the whole number 2. Godot infers the type from the first value.
  11. const ACTION_NAMES := [Creates a constant named ACTION_NAMES. The expression makes a list whose items keep their order. Godot infers the type from the first value.
  12. "Move down the aisle", "Move toward the galley", "Stock water", "Stock a meal",Continues the same instruction on a new line. This is one of the arguments, data entries or expressions started above.
  13. "Stock a blanket", "Serve seat A", "Serve seat B", "Serve seat C", "Serve seat D", "Unload water",Continues the same instruction on a new line. This is one of the arguments, data entries or expressions started above.
  14. "Unload a meal", "Unload a blanket",Continues the same instruction on a new line. This is one of the arguments, data entries or expressions started above.
  15. ]Closes the parentheses, list or dictionary opened above. Any trailing comma separates this item from the next.
  16. static func initial_state() -> Dictionary:Defines initial state, 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.
  17. return {"row": 0, "bag": [0, 0, 0], "done": 0, "turns": 0}Finishes the function and hands its result back to the caller. The expression makes a dictionary that looks up values by key.
  18. static func is_served(state: Dictionary, order_index: int) -> bool:Defines is served, 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.
  19. return (int(state["done"]) & (1 << order_index)) != 0Finishes the function and hands its result back to the caller. The expression evaluates the test to see whether it is true or false.
  20. static func request_count(state: Dictionary, level: Dictionary) -> int:Defines request count, 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.
  21. var count := 0Creates a variable named count. The expression uses the whole number 0. Godot infers the type from the first value.
  22. for index in range(level["orders"].size()):Repeats the indented instructions for each value in range(level["orders"].size()).
  23. if is_served(state, index):Checks is_served(state, index). The indented instructions below run only if this test passes.
  24. count += 1Reads count, adds to its old value, then stores the result back in the same place.
  25. return countFinishes the function and hands its result back to the caller. The expression reads count.
  26. static func is_complete(level: Dictionary, state: Dictionary) -> bool:Defines is complete, 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.
  27. return state["row"] == 0 and request_count(state, level) == level["orders"].size()Finishes the function and hands its result back to the caller. The expression evaluates the test to see whether it is true or false.
  28. static func order_at(level: Dictionary, row: int, seat: int) -> int:Defines order 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.
  29. for index in range(level["orders"].size()):Repeats the indented instructions for each value in range(level["orders"].size()).
  30. var order: Dictionary = level["orders"][index]Creates a variable named order. 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.
  31. if order["row"] == row and order["seat"] == seat:Checks order["row"] == row and order["seat"] == seat. The indented instructions below run only if this test passes.
  32. return indexFinishes the function and hands its result back to the caller. The expression reads index.
  33. return -1Finishes the function and hands its result back to the caller. The expression reads -1.
  34. static func priority_pending(level: Dictionary, state: Dictionary) -> bool:Defines priority pending, 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.
  35. for index in range(level["orders"].size()):Repeats the indented instructions for each value in range(level["orders"].size()).
  36. if level["orders"][index]["priority"] and not is_served(state, index):Checks level["orders"][index]["priority"] and not is_served(state, index). The indented instructions below run only if this test passes.
  37. return trueFinishes the function and hands its result back to the caller. The expression uses the yes-or-no value true.
  38. return falseFinishes the function and hands its result back to the caller. The expression uses the yes-or-no value false.
  39. static func denial(level: Dictionary, state: Dictionary, action: int) -> String:Defines denial, 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.
  40. if action < 0 or action >= ACTION_COUNT:Checks action < 0 or action >= ACTION_COUNT. The indented instructions below run only if this test passes.
  41. return "Choose a cabin action."Finishes the function and hands its result back to the caller. The expression uses the text inside the quotes.
  42. if is_complete(level, state):Checks is_complete(level, state). The indented instructions below run only if this test passes.
  43. return "This flight is complete."Finishes the function and hands its result back to the caller. The expression uses the text inside the quotes.
  44. var row: int = state["row"]Creates a variable named row. 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.
  45. var bag: Array = state["bag"]Creates a variable named bag. 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.
  46. if action == FORWARD:Checks action == FORWARD. The indented instructions below run only if this test passes.
  47. return "You have reached the back of the cabin." if row == level["rows"] else ""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.
  48. if action == BACK:Checks action == BACK. The indented instructions below run only if this test passes.
  49. return "You are in the galley already." if row == 0 else ""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.
  50. if action >= DISCARD:Checks action >= DISCARD. The indented instructions below run only if this test passes.
  51. if row != 0:Checks row != 0. The indented instructions below run only if this test passes.
  52. return "Go to the galley to unload an item."Finishes the function and hands its result back to the caller. The expression uses the text inside the quotes.
  53. return "There is none of that item on the cart." if bag[action - DISCARD] == 0 else ""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.
  54. if action >= SERVE:Checks action >= SERVE. The indented instructions below run only if this test passes.
  55. var index := order_at(level, row, action - SERVE)Creates a variable named index. The expression calls order_at with the values in its parentheses. Godot infers the type from the first value.
  56. if index == -1:Checks index == -1. The indented instructions below run only if this test passes.
  57. return "There is no request at that seat."Finishes the function and hands its result back to the caller. The expression uses the text inside the quotes.
  58. if is_served(state, index):Checks is_served(state, index). The indented instructions below run only if this test passes.
  59. return "You already served that passenger."Finishes the function and hands its result back to the caller. The expression uses the text inside the quotes.
  60. var order: Dictionary = level["orders"][index]Creates a variable named order. 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.
  61. if priority_pending(level, state) and not order["priority"]:Checks priority_pending(level, state) and not order["priority"]. The indented instructions below run only if this test passes.
  62. return "Finish the marked priority orders first."Finishes the function and hands its result back to the caller. The expression uses the text inside the quotes.
  63. if bag[order["item"]] == 0:Checks bag[order["item"]] == 0. The indented instructions below run only if this test passes.
  64. return "This passenger needs %s." % ITEMS[order["item"]].to_lower()Finishes the function and hands its result back to the caller. The expression uses the text inside the quotes.
  65. return ""Finishes the function and hands its result back to the caller. The expression uses the text inside the quotes.
  66. if row != 0:Checks row != 0. The indented instructions below run only if this test passes.
  67. return "Go to the galley to stock the cart."Finishes the function and hands its result back to the caller. The expression uses the text inside the quotes.
  68. if bag[0] + bag[1] + bag[2] >= CART_CAPACITY:Checks bag[0] + bag[1] + bag[2] >= CART_CAPACITY. The indented instructions below run only if this test passes.
  69. return "The cart is full. Serve a passenger or unload an item."Finishes the function and hands its result back to the caller. The expression uses the text inside the quotes.
  70. return ""Finishes the function and hands its result back to the caller. The expression uses the text inside the quotes.
  71. static func next_state(level: Dictionary, state: Dictionary, action: int) -> Dictionary:Defines next state, 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.
  72. if not denial(level, state, action).is_empty():Checks not denial(level, state, action).is_empty(). The indented instructions below run only if this test passes.
  73. return {}Finishes the function and hands its result back to the caller. The expression makes a dictionary that looks up values by key.
  74. var result := state.duplicate(true)Creates a variable named result. The expression copies the collection so a later change can leave the original alone. Godot infers the type from the first value.
  75. var bag: Array = result["bag"]Creates a variable named bag. 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.
  76. if action == FORWARD:Checks action == FORWARD. The indented instructions below run only if this test passes.
  77. result["row"] += 1Reads result["row"], adds to its old value, then stores the result back in the same place.
  78. elif action == BACK:If the earlier branches did not run, checks action == BACK next.
  79. result["row"] -= 1Reads result["row"], subtracts from its old value, then stores the result back in the same place.
  80. elif action >= DISCARD:If the earlier branches did not run, checks action >= DISCARD next.
  81. bag[action - DISCARD] -= 1Continues this part of the script. Read the expression on this line in the context of the nearby declaration or function.
  82. elif action >= SERVE:If the earlier branches did not run, checks action >= SERVE next.
  83. var index := order_at(level, result["row"], action - SERVE)Creates a variable named index. The expression calls order_at with the values in its parentheses. Godot infers the type from the first value.
  84. bag[level["orders"][index]["item"]] -= 1Reads bag[level["orders"][index]["item"]], subtracts from its old value, then stores the result back in the same place.
  85. result["done"] |= 1 << indexContinues this part of the script. Read the expression on this line in the context of the nearby declaration or function.
  86. else:Runs the indented fallback instructions if none of the earlier tests passed.
  87. bag[action - STOCK] += 1Continues this part of the script. Read the expression on this line in the context of the nearby declaration or function.
  88. result["turns"] += 1Reads result["turns"], adds to its old value, then stores the result back in the same place.
  89. return resultFinishes the function and hands its result back to the caller. The expression reads result.
  90. static func key(level: Dictionary, state: Dictionary) -> int: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.
  91. var bag: Array = state["bag"]Creates a variable named bag. 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.
  92. var stock_code: int = bag[0] + 3 * bag[1] + 9 * bag[2]Creates a variable named stock_code. 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.
  93. return (state["done"] * 27 + stock_code) * (level["rows"] + 1) + state["row"]Finishes the function and hands its result back to the caller. The expression looks up the item or key written between the square brackets.
  94. static func shortest_route(level: Dictionary, start: Dictionary) -> Array[int]:Defines shortest route, 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.
  95. var route: Array[int] = []Creates a variable named route. The expression makes a list whose items keep their order. The type after the colon says what kind of value it can hold.
  96. if is_complete(level, start):Checks is_complete(level, start). The indented instructions below run only if this test passes.
  97. return routeFinishes the function and hands its result back to the caller. The expression reads route.
  98. var initial_key := key(level, start)Creates a variable named initial_key. The expression calls key with the values in its parentheses. Godot infers the type from the first value.
  99. var parents := {initial_key: [-1, -1]}Creates a variable named parents. The expression makes a dictionary that looks up values by key. Godot infers the type from the first value.
  100. var queue: Array[Dictionary] = [start]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.
  101. var found := -1Creates a variable named found. The expression reads -1. Godot infers the type from the first value.
  102. var cursor := 0Creates a variable named cursor. The expression uses the whole number 0. Godot infers the type from the first value.
  103. while cursor < queue.size() and found == -1:Keeps repeating while cursor < queue.size() and found == -1 stays true. The loop body should eventually change the result or leave with break.
  104. var current := queue[cursor]Creates a variable named current. The expression looks up the item or key written between the square brackets. Godot infers the type from the first value.
  105. cursor += 1Reads cursor, adds to its old value, then stores the result back in the same place.
  106. for action in range(ACTION_COUNT):Repeats the indented instructions for each value in range(ACTION_COUNT).
  107. var next := next_state(level, current, action)Creates a variable named next. The expression calls next_state with the values in its parentheses. Godot infers the type from the first value.
  108. if next.is_empty():Checks next.is_empty(). The indented instructions below run only if this test passes.
  109. continueSkips the rest of this turn through the loop and moves on to the next item.
  110. var next_key := key(level, next)Creates a variable named next_key. The expression calls key with the values in its parentheses. Godot infers the type from the first value.
  111. if parents.has(next_key):Checks parents.has(next_key). The indented instructions below run only if this test passes.
  112. continueSkips the rest of this turn through the loop and moves on to the next item.
  113. parents[next_key] = [key(level, current), action]Stores the new value in parents[next_key]. The expression makes a list whose items keep their order.
  114. if is_complete(level, next):Checks is_complete(level, next). The indented instructions below run only if this test passes.
  115. found = next_keyStores the new value in found. The expression reads next_key.
  116. breakLeaves the loop immediately and continues with code after the loop.
  117. queue.append(next)Adds an item to the end of a list.
  118. while found != -1:Keeps repeating while found != -1 stays true. The loop body should eventually change the result or leave with break.
  119. var link: Array = parents[found]Creates a variable named link. 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.
  120. if link[1] >= 0:Checks link[1] >= 0. The indented instructions below run only if this test passes.
  121. route.append(link[1])Adds an item to the end of a list.
  122. found = link[0]Stores the new value in found. The expression looks up the item or key written between the square brackets.
  123. route.reverse()Calls route.reverse with the values in its parentheses.
  124. return routeFinishes the function and hands its result back to the caller. The expression reads route.