Skip to reading
BASIC Scripting

Calculate distances and pick a hint

Edition 0.86.4.1 HF1

0.86.4.1 Hotfix 1 edition. Earlier lessons and screenshots retain their original version context; revised references and supplements describe the newer behavior.

Download PDFView PDF page

THE BASIC LANGUAGE

Math helpers handle small but common gameplay jobs. A gauge can stop at its maximum, while a clue can be chosen from several lines.

Code example
FUNCTION Run()
    DIM charge = Clamp(89 + 25, 0, 100)
    DIM ticks = 17 MOD 6
    DIM distance = Distance(Vector3(0,0,0), Vector3(3,0,4))
    RETURN [charge, ticks, distance]
END FUNCTION

The results are 100, 5 and 5. Clamp keeps charge in bounds, MOD gives the remainder, and Distance measures a 3–4–5 displacement between two 3D positions.

Code example
FUNCTION Run()
    DIM clues = ["The ink is fresh.", "The latch is warm."]
    DIM pick = RandomInt(0, 1)
    RETURN clues[pick]
END FUNCTION

RandomInt includes both ends. There are two possible indexes here, 0 and 1. For a list that changes size, use RandomInt(0, Len(clues) - 1) after checking the list contains at least one entry.

Use Floor, Ceil and Round when converting a fraction to a whole step. Store a randomly chosen puzzle answer in game state if players should still get the same answer after loading.

Page 16 of 86Permalink
Go to page