Exam: Grost in the game
Answer them all and press Grade at the end. You can retake it as often as you like: your best score is kept.
When does Gobu call _process(delta)?
_ready runs once when the actor enters the scene; _process runs every frame of the game loop.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.Gobi starts at x = 0 and the game runs at 60 frames per second. What does this code print?
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)
}
}delta it would be 60 per frame, 7200.Your scene has a Sign actor of type Label. Which line brings it into your code?
use actor::, and the type goes after the colon. get_node doesn't exist in Grost, and prefab:: is for .prefab files.The gem prints its value and position in its _ready, and declares pub mut value : int = 1. What does this code print?
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.What does this code print?
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.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.What does this code print?
live points : int = 0
watch points(value: int) {
print(value)
}
fn _ready() void {
set points += 10
points += 5
set points += 1
}set tell the watch. The line without set quietly raises the points to 15, and the last set leaves them at 16.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.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?
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.