Nyxium Documentation

The official documentation for the Nyxium programming language.

v1.3

Get started with Nyxium!

Nyxium is a lightweight programming language designed to be simple to write, easy to understand, and capable of interacting with your system.

Setup

Begin by downloading Nyxium using the Download button at the top of this page. The installer will install Nyxium and add it to your system PATH.

Once Nyxium is installed, open your IDE or text editor of choice and create a file ending in .nyx.

For example:

program.nyx

Write your Nyxium code inside the file, then run it from a terminal:

nyxium program.nyx
Tip: Nyxium files use the .nyx extension.

Nyxium Syntax

This section covers the core syntax currently available in Nyxium.

Output

Use say() to print information to the console.

say("Hello from Nyxium")

Variables can also be passed to say().

var name = "Nyxium"

say(name)

Input

The input command allows a program to receive information from the user.

input name

The value entered by the user can then be used by the program.

input name

say(name)

Variables

Variables are created using the var keyword.

var x = 5

say(x)

Variables can contain values such as numbers and strings.

Changing variables

Existing variables can be given a new value.

var x = 5

var x = x + 1

say(x)

If statements

Nyxium uses if statements to conditionally execute code.

var x = 10

if x == 10
    say("X is 10!")
end

An if block begins with if and ends with end.

Else

Use else when code should run if the condition is not true.

var x = 5

if x == 10
    say("X is 10!")
else
    say("X is not 10!")
end

Elsif

Use elsif to check another condition when the previous condition was not true.

var x = 5

if x == 10
    say("X is 10!")
elsif x == 5
    say("X is 5!")
else
    say("X is something else!")
end

Comparison operators

Nyxium currently supports the following comparison operators:

== > >= < <=

Loops

Nyxium provides basic loop support using loop.

A loop runs its contents the specified number of times.

loop 5
    say("Nyxium")
end

The example above prints Nyxium five times.

Comments

Nyxium supports one-line comments using the @ character.

@ This is a Nyxium comment

say("Hello!")

Anything after @ on that line is treated as a comment.

Night

night is used to define functions in Nyxium.

night hello {
    say("Hello!")
}

hello()
Note: Function syntax and calling conventions may change as the Nyxium language develops.

Get

get loads a Nyxium module so that its functions can be used.

get math

Modules must be loaded before their functions can be used.

Lose

lose disables an imported module. This allows a module to be unloaded after it is no longer required.

get math

lose math

If a module has already been disabled, Nyxium will report that the library is already disabled.

Modules

Nyxium uses the get command to load modules.

get math

Once a module has been loaded, its available functions can be used.

Math

The math module provides basic mathematical operations.

Add

add() adds two numbers together.

get math

add(1, 5)

Subtract

subtract() subtracts the second number from the first.

get math

subtract(5, 1)

Multiply

multiply() multiplies two numbers together.

get math

multiply(4, 5)

Divide

divide() divides the first number by the second.

get math

divide(20, 5)
Available in the math module as of v1.2.5.

Wait

The wait module provides a function for pausing program execution for a specified number of seconds.

get wait

wait(12)

The example above pauses execution for twelve seconds.

Random

The random module provides random-number functionality.

randint

randint() generates a random integer between the two supplied values.

get random

randint(1, 10)
randint() is currently the only function in the random module.

Nyxium File I/O

Nyxium provides file input and output functionality, allowing programs to create and modify files.

Open

The open() function creates or opens a file for use by subsequent file operations.

open(test.txt)
Warning: Opening a file with an existing filename may overwrite the existing file depending on the current implementation. Be careful when using open().

open() does not print output to the console.

Write

The write() function writes data to the currently opened file.

open(test.txt)

write("Hello from Nyxium")

Read

The read() function reads the contents of the currently opened file.

open(test.txt)

read()

Newdir

newdir() creates a new directory.

newdir(projects)

The directory is created using the name supplied to the command.

Discord Module

The discord module allows Nyxium programs to interact with Discord bots.

Warning: Discord functionality is still being developed. Syntax and available features may change in future versions.

Loading the module

Load the Discord module using get.

get discord

Running

Use client.run() to connect your bot to Discord. The function requires your Discord bot token.

client.run("token")
Warning: Never publish your Discord bot token or commit it to a public repository. A hardcoded token can be stolen and used to control your bot. If a token is exposed, reset it immediately through the Discord Developer Portal.
Warning: The messageContent intent is currently required. Enable it in the Discord Developer Portal.
Note: The token can also be stored in a variable.
var token = "your token"

client.run(token)

Commands

Nyxium uses client.command() to create regular Discord commands.

client.command("hello"; "Hello from Nyxium!")

When the command is registered, users can run it using the bot's configured command prefix.

User mentions

The {userid} placeholder can be used to mention the user who triggered the command.

client.command("hello"; "Hello {userid}!")

When a user runs the command, {userid} is replaced with a Discord mention of that user.

Slash commands

Discord slash commands can be created using client.slash().

client.slash("hello"; "Says hello"; "Hello from Nyxium!")

The arguments are the command name, its description, and the response sent when the command is used.

User mentions

Slash commands also support the {userid} placeholder.

client.slash("hello"; "Says hello"; "Hello {userid}!")

Syncing commands

Use client.sync() to synchronize slash commands with Discord.

client.sync()
Note: Slash commands may not appear until they have been synchronized.

Events

Nyxium can respond to Discord events using client.event().

The function takes the event name, a channel ID, and the response.

client.event("onReady"; "1551609425758916661"; "Bot is online!")

onReady

The onReady event runs when the bot has connected to Discord. The response is sent to the specified channel.

client.event("onReady"; "1551609425758916661"; "Bot is online!")

memberJoin

The memberJoin event runs when a new member joins the server.

client.event("memberJoin"; "1551609425758916661"; "Welcome to the server!")

Member

Use {member} to mention the member

Channel IDs

Events that send messages to a channel require the channel's Discord ID.

client.event("onReady"; "1551609425758916661"; "Hello all!")

Discord Developer Mode can be enabled to copy channel IDs.

Warning: Make sure you provide a channel ID rather than a channel name.

Example bot

The following example combines commands, slash commands, events, and command synchronization.

get discord

var token = "token"

client.command("hello"; "Hello {userid}!")

client.slash("test"; "A test command"; "Testing {userid}!")

client.event("onReady"; "1551609425758916661"; "Bot is online!")

client.event("memberJoin"; "1551609425758916661"; "Welcome to the server!")

client.sync()

client.run(token)
Note: Discord functionality is actively being developed. Additional events, command features, and functionality may be added in future versions.

Nyxium Errors

Nyxium provides error messages when something goes wrong during execution.

Module not found

This error means that a module was used without first loading it with get.

Nyxium line 5: Wait module not found, try using `get wait`

Fix the error by loading the module before using it.

get wait

wait(5)

File not found

This error usually means that Nyxium could not find the file specified by the command.

Error: Nyxium file not found

Check the filename and make sure the file exists in the expected location.

Unknown command

An unknown-command error occurs when Nyxium encounters syntax or a command that it does not recognise.

Unknown command: Line 6

Check the line reported by the interpreter and make sure the command is spelled correctly.

Library disabled

This error occurs when lose is used on a module that has already been disabled.

Nyxium line 15: Math library already disabled!

Make sure the module is currently loaded before attempting to disable it.

Changelog

Version 1.3

File I/O

Nyxium version 1.3 introduced File I/O features such as read() and write().

Documentation

The changelog section was added to the Nyxium documentation in version 1.3.

Input

input was introduced in this version.

Version 1.27

Randint

Nyxium introduced the randint() function within the random module.

Wait

Nyxium introduced the wait() function within the wait module.

Version 1.25

Math

Several mathematical functions were added to the math module.

Add

The add() function was introduced.

Subtract

The subtract() function was introduced.

Multiply

The multiply() function was introduced.

Divide

The divide() function was introduced.