StormScript Docs


expand_moreIntroduction

expand_moreThe Language

Introduction

Welcome


Welcome to the StormScript docs. StormScript is a free, open-source scriping language that is designed to be easy to use and powerful.


Hello, World!


Hello world in StormScript is exactly as follows.


do{
    printl "Hello, World!";
}
                

In this example, I used the do{} function to run the printl command to print "Hello, World".




The Language

Intro to Commands


Like any other language, StormScript uses commands. New commands are added every major and minor release.


Main Function Scope


The do{} Scope

The code inside of the do{} scope is the code that is executed the second the code is run.

The loop(); Function

The other option to end a scope is with loop(); which will run the code with two options.

loop(n); will run the scope n times.

loop(inf); will run the scope forever.

Example:

In this example, the program takes in user input using the in command and then prints out a response based on what the value of the input is using a conditional statement.


do{
    in x;

    if x is "hi"{
        printl "Hello!";
    }else if x is "bye"{
        printl "Goodbye!";
    }else{
        printl "I don't know what you said. Suggestions hi, bye";
    }
}
                

If you run this example, you will see that when the program is run, the content inside of do{} is also run.


Output Streams


print

The print command allows for writing to the console. You can print string literals with print "string literal"; or you can print variables with print varname;. You can also concatinate strings with the comma operator as follows: print varname, " has cool contents!\n.";. A newline can be added to a string literal with "\n"

Example:


do{
    name: "bob";

    print "Hello, ", name, "\n";
}
                

printl

The printl command is identical to print except that it inserts a new line automatically.

Example:


do{
    name: "bob";

    print "Hello, ", name;
}
                

sys

The sys command will execute system commands.

Example:


do{
    sys "echo hi";
}
                

Input Streams


in

The in command has you create a variable of any type and takes command line input for its contents. As of StormScript v0.4.0, you no longer have to specify a type.

Example:


do{
    in x;

    printl x;
}
                

Values


Types

bool

A boolean can only have a value of true or false.

str

A string can have any text value. Strings indexes can be accessed with the [] operator. The length of a string can be accessed with name|length

int

An integer can store any non-decimal numeral value

list

A list has multiple objects that can be accessed with a subscript ([]). The length of a string can be accessed with name|length.

Namespaces

Variables have two different scopes, the global namespace and the local namespace. Variables within the global namespace can be referenced in every part of the file, while variables in the local namespace can only be referenced within their scope.

Declaration

As of StormScript v0.4.0, values can be modified and declared using the : operator and the value without stating the type.

Example


x: 1;

do{
    in y;
    z: true;
    d: [3, 4, 5];

    printl x;
    printl d[0];
    printl y;
    printl z;

    x: 2;

    printl x;
}
                

Functions


func

The func keyword declares a function.

Example:


func x{
    printl "hi";
}

do{
    x;
}
                

return

Functions can return values to be printed by using the return keyword.


func x{
    y: 3;
    return y;
}

do{
    print x;
}
                

Function Arguments

Functions can use arguments, which can be sent when an instance is run using the => operator.

Example:


func f => x{
    printl x;
}

do{
    f => x: 3;
}
                

Forward Declaration

You can declare functions in advance with forward declaration. Functions are declared like normal, but the body of the function is left out and a semicolon is put in place of curly brackets.


func hello;
func args => a;

do {
    hello;
    args => a: "test";
}

args => a {
    printl a;
}

hello {
    printl "Hello, World!";
}
                

Conditional Statements


if

The if keyword compares 2 values.

else

else runs when if is not true.

Example:


do{
    x: "hi";

    if x not "hi"{
        printl "This doesn't run";
    }else{
        printl "This does";
    }
}
                

Conditional statements as values

Condition statements can be used as values with two methods.

1. Storing the value in a bool

The value of a conditional statement can be stored in a boolean by declaring with a statement


do{
    x: 3;
    y: x is 3;

    printl y;
}
                

2. Ternary Operator

The value of a variable can depend on the value of another through the ternary operator.


do{
    x: 4;
    y: x is 3 ? "It is" : "It isn't";

    printl y;
}
                

while

Conditional statements can be used in a while loop, a loop that will run while a statement is true.


do{
    x: 3;
    while x lesseq 10 {
        x+: 1;
        printl x;
    }
}
                

Conditional Operators

is

The is operator checks if two values are equal.

not

This operator checks if two values are not equal.

less and lesseq

These operators check if an integer is less than another or less than or equal to another respectively.

greater and greatereq

These operators check if an integer is greater than another or greater than or equal to another respectively.


Classes


type

The type keyword creates a class. Classes can be used as types, meaning that you can declare a class-type like any other variable.

Example:

In this example, there is a class named person with the objects age, name, and gender. You must specify type for objects


type person{
    str name;
    str gender;

    int age;
}

do{
    person p1;
    person p2;

    p1|age: 24;
    p1|name: "Bob";
    p1|gender: "male";

    p2|age: 36;
    p2|name: "Sue";
    p2|gender: "female";

    printl p1|name, " is a ", p1|age, " year old ", p1|gender, ".";
    printl p2|name, " is a ", p2|age, " year old ", p2|gender, ".";
}
                

Class Methods

Class methods are declared like any other function except that they are declared inside of a type scope.


type person {
    int age;
    str name;

    func birthday {
        age+: 1;
    }
}

do {
    person p;
    p|age: 22;
    p|name: "Joe";

    printl p|name, " is ", p|age, " years old!";

    p|birthday;

    printl "It's ", p|name, "'s birthday. ", p|name, " is ", p|age, " years old!";
}
                

Class Constructors

Constructors allow the value of a class object to be defined at the same time as the class type. Class constructors use the def keyword.


type person {
    def str name;
    def int age;

    func birthday {
        age+: 1;
    }
}

do{
    person p: "bob", 18;
    
    printl p|name, " is ", p|age, " years old.";
    p|birthday;
    printl p|name, " is ", p|age, " years old.";
}
                

Files


read

Use read "filename" to read a file. Returns a string with the contents of a file

write

Use write "filename" to write to a file. Clears the contents of the file.


Modules


Import a module with the mod keyword followed by the module name. This will import all functions and global variables in that file and will allow them for use.


Miscellaneous


wait

Use wait followed by an integer to sleep for that many seconds.

random

Returns a random boolean.

randomrange => min, max

returns a random number between min and max