Skip to content

GigaScript Documentation

aName edited this page Feb 29, 2024 · 13 revisions

File extension: .g

Syntax

GigaScript has very simple syntax, similar to those of other popular languages.

Variables

A variable can hold any value supported by GigaScript.

Declaring Mutable Variables

let varName = value;

varName can be any name you want, but must follow the following requirements:

  • Cannot start with a number
  • Must start a letter or an underscore "_". value can be any value you want that is supported by GigaScript.
let anotherVar;

Mutable variables do not need to have a variable assigned when they are declared.

Important

All variable declarations must end with a semicolon ";".

Declaring Constant Variables

const varName = value;

varName can be any name you want, but must follow the following requirements:

  • Cannot start with a number
  • Must start a letter or an underscore "_". value can be any value you want that is supported by GigaScript.

Important

Constant variables must have a value when declared.

Reassigning Mutable Variables

Caution

Constant variables cannot be reassigned!

varName = newValue

Note

Reassignments shouldn't end with a semicolon ";".

Accessing Variables

To access a variable, simply reference it using the variable name.

varName

varName should be the name of your variable. You can use varName anywhere in your code. For examples, see examples.

Functions

Functions are very useful when you want to repeat the same task multiple times in different parts of your code.

Declaring Functions

func funcName(params) {
    *code*
}

funcName could be any name following these naming rules:

  • Cannot start with a number
  • Must start a letter or an underscore "_". params can be any length of parameters you need passed into your function, or no parameters at all, following the same naming rules as above.

Calling Functions

funcName(params)

funcName could be any name following these naming rules:

  • Cannot start with a number
  • Must start a letter or an underscore "_". params can be any length of parameters you need passed into your function, or no parameters at all, following the same naming rules as above.

Classes

Declaring a new Class

class ClassName(){
   public publicProp = "this can be any value";
   private privateProp = "this can be any value but can't be accessed outside of the class";

   public publicMethod(params){
      code (See [Functions](https://github.com/aName2050/GigaScript/wiki/GigaScript-Documentation#Functions) for more info on functions.)
   }

   private privateMethod(params){
      code (See [Functions](https://github.com/aName2050/GigaScript/wiki/GigaScript-Documentation#Functions) for more info on functions.)
   }
}

ClassName can be any name, while still following these naming rules:

  • Cannot start with a number
  • Must start a letter or an underscore "_". public properties and methods can be accessed when a new class instance is created. private properties and methods cannot be accessed when a new class instance is created.

Creating a new Instance of a Class

let className = new ClassName();

ClassName is the name of your class. new ClassName() will create a new object containing all the class's public properties and methods.

Accessing a Class's Public Properties and Methods

  1. Create a new instance of the class and set it as the value of any variable.
let aCoolClass = new ClassName();
  1. Access the public properties and methods of the class as if you were accessing the properties of an object.
aCoolClass.publicProp
aCoolClass.publicMethod(params)

Conditional Statements

condition is where you would check if a condition is true. See examples.

If Statement

if(condition) {
   code
}

If-Else Statement

if(condition) {
   code
} else {
   code
}

If-Else If-...-Else Statement

if(condition) {
   code
} else if (other_condition) {
   code
} else {
   code
}

Tip

You don't need to include an else statement in every conditional statement.

Reserved Keywords

These are reserved keywords in GigaScript that cannot be the names of any class, function, or variable.

let
const
func
class
true
false
undefined
new
null
private
public
if
else
while
for
continue
break
import
export
from

Caution

Using any of these keywords as a class, function, or variable identifier will result in an error!

Examples

Clone this wiki locally