Vǫrðr Forge Steam page

Rûn Language

Rûn Tutorial: The Wishing Well

This tutorial builds one small thing from nothing: a well the player can throw a coin into. It takes the coin, rolls for luck, sometimes gives a ring, counts the wishes across saves, and runs dry after three. It uses an event script for what the player sees and a program for the luck, the way most of a game is built.

You need a project with a prop to be the well. Set its Properties to Interactable > Interactable on and Interactable > Event to well (see Events and Triggers). Every step below can also be tried without a prop: in Test mode, type run well at the console.

Step 1: the item

The well's prize is a ring. Make it on the Items page of the asset manager, or at the console:

itemdef well_ring Silver_Ring
savedata items

Step 2: the well speaks

Make assets/events/well.run (Outliner > Add… > Event, then rename it) with one section:

[use]
say The well is deep and dark.
The well is deep and dark.

Press Test, walk up to the well and press E: the line appears at the bottom of the screen.

Step 3: a coin

The well wants a coin. gold is a reading of how much she has; the verb gold -1 takes one. end stops the section early.

[use]
if gold < 1
  say The well wants a coin.
  end
gold -1
say The coin falls a long way.
The coin falls a long way.

Step 4: luck

rand(20) is a whole number from 0 to 19, so rand(20) + 1 is a roll from 1 to 20. On 18 or more she gets the ring.

[use]
if gold < 1
  say The well wants a coin.
  end
gold -1
set wish rand(20) + 1
if wish >= 18
  give well_ring 1
  say The water glows. A ring!
else
  say Ripples, and nothing more.

wish is a variable: set made it, and {wish} in a say line would show it.

Step 5: three wishes

add wishes 1 counts the wishes. The count is an event script variable, so it is kept when she saves and loads (see Rûn Saving State).

[use]
if wishes >= 3
  say The well is dry.
  end
if gold < 1
  say The well wants a coin.
  end
gold -1
add wishes 1
set wish rand(20) + 1
if wish >= 18
  give well_ring 1
  say The water glows. A ring!
else
  say Ripples, and nothing more.

Step 6: let the checker look

Change give to giv, save, and type check well at the console, or look at the Text Editor's gutter:

[use]
giv well_ring 1
ERROR line 2: no verb called "giv"  - did you mean give?
1 finding(s)

Put the e back.

Step 7: the luck as a program

The luck could grow: a lucky charm, a better chance at night. Rules like that are easier to write in a program, and a program named like an event answers that event in place of the event script. Make assets/scripts/well.run, and the well runs it from now on:

// the wishing well: a program decides, an event script speaks
on use {
    if (World.Flag("well_dry")) {
        World.Fire("well_words", "dry")
        return
    }
    if (Player.gold < 1) {
        World.Fire("well_words", "poor")
        return
    }
    Player.gold = Player.gold - 1
    number wish = floor(random(1, 21))
    number need = 18
    if (Sky.hour < 6 || Sky.hour > 20) need = 16
    if (wish >= need) {
        Player.Give("well_ring", 1)
        World.Fire("well_words", "won")
    } else {
        World.Fire("well_words", "lost")
    }
}

A program cannot put words on the screen, and its variables do not last past one use, so it hands both jobs to an event script with World.Fire. Make assets/events/well_words.run:

[dry]
say The well is dry.

[poor]
say The well wants a coin.

[won]
say The water glows. A ring!
run well_words count

[lost]
say Ripples, and nothing more.
run well_words count

[count]
add wishes 1
if wishes >= 3
  flag set well_dry

The program decides; the event script speaks and counts, and its count rides the save. When the third wish is counted, the flag well_dry goes up, and the program sees it next time.

Step 8: try it

Start a new test, and throw four coins in from the console:

print(Player.gold)
World.Fire("well", "use")
World.Fire("well", "use")
World.Fire("well", "use")
World.Fire("well", "use")
print(Player.gold)
100
97

She started with 100 gold. Three wishes took three coins; the third raised well_dry, and the fourth throw found the well dry and took nothing. World.Fire("well", "use") is what the well's prop does when she presses E at it.

Where to go next