Background
Background

Making Structs in Verse, Simplified

A Verse struct groups fields; FruitBasket records fruit counts and a supplied weight.

Put the import and declarations at module level, outside your device class. Call Example() from existing device code in the same module.

Define the basket

using { /Verse.org/Verse }

FruitBasket<public> := struct<concrete>:
    Apples<public> : int = 0
    Oranges<public> : int = 0
    Bananas<public> : int = 0
    BasketWeight<public> : float = 0.0

<concrete> requires field defaults; here, FruitBasket{} and omitted fields use zero.

Add baskets

This overload adds all four fields into a new basket, leaving A and B unchanged.

operator'+'<public>(
    A : FruitBasket,
    B : FruitBasket
)<transacts> : FruitBasket =
    FruitBasket{
        Apples := A.Apples + B.Apples,
        Oranges := A.Oranges + B.Oranges,
        Bananas := A.Bananas + B.Bananas,
        BasketWeight := A.BasketWeight + B.BasketWeight
    }

Example

Example():void =
    A := FruitBasket{
        Apples := 2,
        Oranges := 1,
        BasketWeight := 1.5
    }

    B := FruitBasket{
        Apples := 1,
        Bananas := 3,
        BasketWeight := 2.0
    }

    Combined := A + B
    Print("Apples: {Combined.Apples}")

Expected from the code, using kilograms: 3 apples, 1 orange, 3 bananas and 3.5 kg.

Weight is not calculated from counts.

This sample has not been compiled or run in UEFN.

Move over the bright dot and follow the line. P pauses. Escape closes the game.

Sigil Trace

Move over the sigil before time runs out.

Score0000
Spells00
Best on this browser0000
I · KINDLE SPELL 01
START

Trace the Sigil with your mouse

Start at the glowing dot and follow the line. No click needed.

or press Enter
Move your mouse onto the bright dot. No click needed.