CraftScript
  • CraftScript
  • Syntax
    • Kinds
    • Keywords
    • Language Features
  • Tutorials
    • Getting Started
      • Assurance Keywords
      • Value Keywords
      • Condition Keywords
      • Other Keywords
    • Using the Language
      • The Do Block
    • Importing External Scripts
    • Adding CraftScript to a Server
    • Environments and Contexts
  • Libraries
    • Reflection
    • Debug
    • Math
    • Parser
    • Global
Powered by GitBook
On this page
  1. Tutorials
  2. Getting Started

Assurance Keywords

Keywords used to test and guarantee correct performance.

There are 3 assurance keywords. These are used to guarantee a resource is present or correct.

Assert

Assertions make sure a value is equal to (or evaluates to) true.

assert true
assert 5 == 5
assert "hello" == "hello"
assert true == true
assert false == false
assert true & true
assert true | false
assert false ^ true
assert 10 > 5
assert 5 <= 5
assert 5 != "hello"

Assertions are designed for testing whether a program or its environment is correct.

If an assertion fails the script will stop and print an error (e.g. assert false).

Require

Requirements make sure a variable exists.

name = "Jeremy"
require [name]

Requirements are designed for testing whether a function (or script) has been given the correct inputs.

If a requirement fails the script will stop and print an error.

Requirements can also be used to convert anonymous arguments into named variables.

func = function {
    require [name]
    /say hello {name}
}
run func [name="Jeremy"]
run func ["Jeremy"]

Import

Imports fetch a resource from a different script or program.

import [math]

result = run math[floor] 5.6

assert result == 5

There are several built-in libraries that you can import (e.g. math, parser).

You can also import the result of a different script.

sum.script
10 + 5
main.script
import [sum]

assert sum == 15

Importing a script stores its result in a named variable.

PreviousGetting StartedNextValue Keywords

Last updated 1 year ago