Types: numbers, text, and logic

Every value in Verse has a type — what kind of thing it is. Verse is strict about types, and that strictness is a gift: it catches whole categories of mistakes before your game ever runs. Let's meet the four types you'll use most.

The four core types

int — whole numbers

Counting numbers, positive or negative, no decimal point: 0, 7, -3, 100.

        Lives := 3          # an int
        var Score : int = 0

float — decimal numbers

Numbers with a fractional part. Write the decimal point so Verse knows it's a float: 3.0, 0.5, -12.75.

        Gravity := 9.8      # a float
        Speed : float = 1.0

5 is an int; 5.0 is a float. They are different types — a small thing that trips up beginners, so watch the decimal point.

string — text

Any text, always inside double quotes: "Hello", "Level 1", "" (empty).

        Title := "Coin Rush"

logic — true or false

A yes/no value. Verse's two logic values are true and false.

        IsRanked := true
        var GameOver : logic = false

Note: in many languages this type is called bool. In Verse it's logic, with values true and false. Unlike numbers and text, you don't usually Print a logic value directly — instead you use it to make decisions with if, which is the heart of the next module. So we'll store one here but hold off on printing it.

Printing values inside text: string interpolation

Print wants a string. So how do you print a number? You drop it into a string using curly braces { } — called string interpolation:

        Score := 150
        Print("Your score is {Score}!")     # → Your score is 150!

Whatever's inside { } is calculated and woven into the text. You can interpolate more than one:

        Title := "Coin Rush"
        Lives := 3
        Print("{Title} — you have {Lives} lives left")
        # → Coin Rush — you have 3 lives left

This is the way you'll inspect values while learning. Print early, print often.

Simple arithmetic

For int and float, the familiar operators work:

        Apples := 5
        Bought := 3
        Print("Total: {Apples + Bought}")   # → Total: 8
        Print("Double: {Apples * 2}")       # → Double: 10
  • + add · - subtract · * multiply
  • Division (/) behaves specially in Verse (it has to handle "divide by zero"), so we'll come back to it later. Stick to + - * for now.

Types must match

Verse won't let you mix types that don't belong together. This fails to build on purpose:

        Name := "Avery"
        Print(Name + 5)     # ✗ can't add a number to text

That error is Verse protecting you. If you want the number in the text, interpolate instead:

        Print("{Name} scored {5}")   # ✓

Try it

Add this to your device's OnBegin and build:

        Title := "My Island"
        Players := 4
        Difficulty := 1.5
        IsOpen := true     # a logic value — stored, but we won't print it yet
        Print("{Title}: up to {Players} players, difficulty {Difficulty}")

Check the log. You just used all four types, and printed a string, an int, and a float in one line. (IsOpen is ready for next module, where logic finally gets to do its job.)


Official reference:

Comfortable with int, float, string, and logic — and printing them? Mark complete. Next is the Module 1 project, where you'll use all of this at once.

Check your understanding

  1. Multiple choice1 / 4
    Which of these is a float (a decimal number)?
  2. Predict the output2 / 4
    What appears in the log?
    Apples := 5
    Bought := 3
    Print("Total: {Apples + Bought}")
  3. Multiple choice3 / 4
    In Verse, the type that holds true or false is called…
  4. Fill in the blank4 / 4
    Inside a string, what pair of symbols do you wrap a value in so it gets calculated and printed? (Type the symbols, or name them.)