Menu
CoddyTech

One Shot

Part of the Game Rules section of Coddy's Godot journey. Lesson 4 of 29.

A timer starts over every time it runs out. That suits a blinking light, but a bomb should go off only once.

Set one_shot to true and the timer runs out once, then stops:

$Timer.one_shot = true

Calling start() again sets it going for one more run.

In this castle, E opens the gate and starts a two second timer. When the timer runs out, it closes the gate.

challenge icon

Challenge

Easy

Make the gate close only once.

  1. In _ready(), set $Timer.one_shot to true.
  2. Leave the rest as it is, so E still opens the gate.

Press Play, then E: two seconds later the gate closes and stays shut. Then Check.

Try it yourself

extends Node2D

func _ready():
	$Timer.wait_time = 2
	$Timer.timeout.connect(_on_timer_timeout)

func _process(delta):
	if Input.is_action_just_pressed("action"):
		$Gate.position.y = 20
		$Timer.start()

func _on_timer_timeout():
	$Gate.position.y += 140

All lessons in Game Rules

Practice on your own: Godot playground