Skip to content
Download
Grost course

Exam: Grost in the game

Module 310 questionspass with 70%

Answer them all and press Grade at the end. You can retake it as often as you like: your best score is kept.

Question 1 of 10

When does Gobu call _process(delta)?

_ready runs once when the actor enters the scene; _process runs every frame of the game loop.
Question 2 of 10

What is the delta that _process receives?

delta is in seconds: at 60 frames per second, about 0.0167. Multiplying by delta makes the speed per second instead of per frame.
Question 3 of 10

Gobi starts at x = 0 and the game runs at 60 frames per second. What does this code print?

main.gro
use actor::Gobi as gobi : Spatial2D

mut frames : int = 0

fn _ready() void {
  print(gobi.position.x)
}

fn _process(delta: float) void {
  gobi.position.x += 60.0 * delta
  frames += 1
  if frames == 120 {
    print(gobi.position.x)
  }
}
It moves 60 pixels per second, and 120 frames are 2 seconds: 120 pixels. Without the delta it would be 60 per frame, 7200.
Question 4 of 10

Your scene has a Sign actor of type Label. Which line brings it into your code?

The scene's actors come in with use actor::, and the type goes after the colon. get_node doesn't exist in Grost, and prefab:: is for .prefab files.
Question 5 of 10

The gem prints its value and position in its _ready, and declares pub mut value : int = 1. What does this code print?

main.gro
use prefab::Gem as gem

fn _ready() void {
  mut g := gem.instantiate()
  g.value = 3
  GetWorld.add_child(g)
}
instantiate() makes the copy, g.value = 3 changes its pub field and GetWorld.add_child adds it to the scene. That's when its _ready runs, and it already sees the 3.
Question 6 of 10

What does this code print?

main.gro
signal hit(damage: int)

mut lives : int = 5

on self.hit(damage: int) {
  lives -= damage
}

fn _ready() void {
  emit hit(2)
  hit.emit(1)
  print(lives)
}
emit hit(2) and hit.emit(1) are two ways of emitting. The on runs for each one: 5 - 2 - 1 = 2.
Question 7 of 10

You brought in a button with use actor::Play as play : Button. How do you react when it's pressed?

on connects a block to a signal, and a Button emits pressed when it's pressed. watch and upon are for live variables, and emit sends a signal out instead of listening to it.
Question 8 of 10

What does this code print?

main.gro
live points : int = 0

watch points(value: int) {
  print(value)
}

fn _ready() void {
  set points += 10
  points += 5
  set points += 1
}
Only changes with set tell the watch. The line without set quietly raises the points to 15, and the last set leaves them at 16.
Question 9 of 10

What's the difference between watch and upon?

watch lives(value: int) reacts to every change of lives. upon lives == 0 runs its block once and never again.
Question 10 of 10

Gobi collects coins and the on-screen score display shows them. Where do you keep that number so both can share it without knowing about each other?

A global interface is a shared block of data: Gobi writes to it and the score display watches it with watch, without either knowing about the other. With a pub field of Gobi, the score display would have to know Gobi.