CodeBlanks Logo Icon CodeBlanks

Summary - GDScript

Reinforce GDScript basics with a summary task.

Summary: GDScript Fundamentals

In this module, you mastered the fundamentals of GDScript, Godot Engine's native language. Scripts commence with extends Node, declare state with var, and organize routines via func.

extends Node

var score: int = 0

func add_score(amount: int) -> void:
    score += amount
    print("Score: " + str(score))

print() supplies console tracing, while : and -> establish type safety across scripts.

Practice Print GDScript summary function

Define the function get_summary(name: String, level: int) -> String returning "Hero: " + name + " | Lv: " + str(level). In _ready, call it with "Warrior" and 10 and print the output.

Starter code

Player.cs
extends Node

# get_summary fonksiyonunu ve _ready metodunu tanimla

Sample solution

Player.cs
extends Node

func get_summary(name: String, level: int) -> String:
    return "Hero: " + name + " | Lv: " + str(level)

func _ready():
    var result: String = get_summary("Warrior", 10)
    print(result)

Expected output

Hero: Warrior | Lv: 10

Questions and answers

Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.

1 Which statement regarding GDScript is correct?

  • It uses Python-like indentation, inherits from Node classes via extends, and declares functions with func. Correct answer
  • It operates exclusively in web browsers and cannot be executed directly in Godot.
  • Variables exclusively use const instead of var and custom functions cannot be written.
  • Code blocks are delineated with braces { } and semicolons are strictly required.

Explanation: GDScript is Godot's language featuring Python-like clean indentation, using extends and func keywords.

2 Add return type hint

Question
func get_name() -> ____:
Answer
func get_name() -> String:

Explanation: In GDScript, the return type of functions returning text is specified as 'String'.

3 GDScript general summary

Term Meaning
extends Node Declares deriving from Node class
var Keyword to declare new variables
func Keyword used to define functions
print Function printing output to console

All lessons in Beginner