Bitflinger Games docs

Say hello

You'll learn: how a game tells your code that something happened, and how your code can answer.
Time: 10 minutes.

Try itOpen this lesson in the Bitflinger Games app to try it.

Play it first

When the game starts, "Hello!" appears at the top of the screen. Here's the code that does it:

func _ready() -> void:
	Variations.event.connect(_on_event)


func _on_event(event_name: String, payload: Dictionary) -> void:
	if event_name == "world.ready":
		Variations.emit_event("hud.message", {"text": "Hello!"})

Events

While a game runs, things happen: the world finishes building, the player jumps, a coin is collected. Each time, the game sends an event, a message with a name that every layer can hear.

This code does two things:

  1. In _ready, Variations.event.connect(_on_event) means "whenever there's an event, run _on_event".
  2. _on_event is a function of your own: a named piece of code that runs when something calls it. It's given the event's name and its details. When the name is "world.ready", the world has just been built, so it sends an event of its own, "hud.message", with the text to show.

Starter World listens for hud.message and shows the text. Any layer can send it.

Change it

Change "Hello!" to your own message, such as "Find all ten coins". Keep the quotes.

Try this

Starter World sends player.jumped every time you jump. Add a second check to _on_event, lined up with the first if:

	if event_name == "player.jumped":
		Variations.emit_event("hud.message", {"text": "Boing"})

Play, and jump.

Events in Starter World

EventWhen it's sentDetails
world.readyThe world has been builtworld, player
player.jumpedThe player jumpsplayer, count (1, or 2 for a double jump)
player.fellThe player fell off the worldplayer
collectedA coin was picked upitem
hud.messageSend it to show texttext

What you learned

That's the end of Stage 1. Stage 2, building a place of your own, is coming next. Until then, the Guide shows everything a layer can do.