Skip to content

Namespaces

mystborn edited this page Jun 22, 2018 · 2 revisions

A namespace is a convenient way to seperate code into named sections, particularly to avoid naming conflicts. The concept is almost the exact smae as the one used in c# and other similar languages.

Defining a Namespace

To define a namespace, write namespace follwed by the name of the namespace (try saying that 10 times fast). Then, inside of a block, you can declare objects, scripts, and other namespaces that will be defined inside of the parent namespace. For example:

namespace Example {
    script scr_namespace {
        print("Called from a namespace");
    }

    object obj_namespace {
        script create {
            print("Created from a namespace");
        }
    }

    //You can also have nested namespaces
    namespace Inner {
        //To access an element from here, it's path would be Example.Inner.element_name
    }
}

Accessing Namespace Members

Direct Access

To access a namespace member directly, you can write the namespace name, a dot, then the member name like so: Example.obj_namespace.

Using

To access all of the members of a namespace, you can add a using statement to the top of your file. Note that it MUST be the first thing in a file. For example:

using Example;

script scr_global {
    scr_namespace();
}

vs

scr_global {
    Example.scr_namespace();
}
Clone this wiki locally