Menu
CoddyTech

Project Overview

Part of the Logic & Flow section of Coddy's GDScript journey. Lesson 42 of 78.

challenge icon

Challenge

Easy

The Student Records Manager keeps data about students: their age, their grades and the courses they take. Over the next steps you will add students, add grades, check enrollment, calculate averages, list the students of a course and find the top students.

The program reads commands, one per line, such as add Alice 20 Math Physics or grade Alice 90. In this step, set up the records and the command loop:

  1. At the top level of the script, between extends Node and func _ready():, declare an empty dictionary: var student_records := {}. A variable declared there, outside every function, can be used by every function of the script, which the next steps need.
  2. In _ready(), start a while true: loop. In each iteration, read one line, split it at the spaces and turn the result into an array: var parts := Array(OS.read_string_from_stdin().split(" ", false))
  3. Use match parts: with two array patterns:
    • ["show"]: print student_records
    • ["exit"]: print Goodbye! and leave the loop with break

Ignore every other command for now. Every test ends with exit. For the commands

show
exit

the output is:

{  }
Goodbye!

Try it yourself

extends Node

# Declare student_records here

func _ready():
	# Read commands in a loop until exit
	pass

All lessons in Logic & Flow

Practice on your own: Online GDScript compiler