# \_G

### assert

`assert(expression: any[, text: string, ...]): any`

<table><thead><tr><th width="150">Name</th><th width="150">Type</th><th>Description</th></tr></thead><tbody><tr><td><strong>expression</strong></td><td><strong><code>any</code></strong></td><td>The expression to assert.</td></tr><tr><td><strong>text</strong></td><td><strong><code>text</code></strong></td><td>The error message to throw when assertion fails. This is only type-checked if the assertion fails.</td></tr><tr><td><strong>...</strong></td><td><strong><code>any</code></strong></td><td>Any arguments past the error message will be returned by a successful assert.</td></tr></tbody></table>

If the result of the first argument is false or nil, an error is thrown with the second argument as the message.

### error

`error(text: any[, level: number])`

<table><thead><tr><th width="150">Name</th><th width="150">Type</th><th>Description</th></tr></thead><tbody><tr><td><strong>text</strong></td><td><strong><code>string</code></strong></td><td>The error message to throw.</td></tr><tr><td><strong>level</strong></td><td><strong><code>number</code></strong></td><td>The level to throw the error at.</td></tr></tbody></table>

Throws a Lua error and breaks out of the current call stack.

### getmetatable

`getmetatable(object: any): any`

<table><thead><tr><th width="158">Name</th><th width="150">Type</th><th>Description</th></tr></thead><tbody><tr><td><strong>object</strong></td><td><strong><code>any</code></strong></td><td>The value to return the metatable of.</td></tr></tbody></table>

Returns the metatable of an object. This function obeys the metatable's \_\_metatable field, and will return that field if the metatable has it set.

### ipairs

`ipairs(tbl: table): function, table, number`

<table><thead><tr><th width="165">Name</th><th width="150">Type</th><th>Description</th></tr></thead><tbody><tr><td><strong>tbl</strong></td><td><strong><code>table</code></strong></td><td>The table to iterate over.</td></tr></tbody></table>

Returns an iterator function for a for loop, to return ordered key-value pairs from a table.

### print

`print(text: string[, ...])`

<table><thead><tr><th width="177.60767828800178">Name</th><th width="150">Type</th><th>Description</th></tr></thead><tbody><tr><td><strong>text</strong></td><td><strong><code>string</code></strong></td><td>Text to print into the console.</td></tr><tr><td><strong>...</strong></td><td><strong><code>any</code></strong></td><td>Optional arguments to concatenate with <code>text</code>.</td></tr></tbody></table>

Prints the text to the console.

### print\_error

`print_error(text: string[, ...])`

<table><thead><tr><th width="177.60767828800178">Name</th><th width="150">Type</th><th>Description</th></tr></thead><tbody><tr><td><strong>text</strong></td><td><strong><code>string</code></strong></td><td>Text to print into the console.</td></tr><tr><td><strong>...</strong></td><td><strong><code>any</code></strong></td><td>Optional arguments to concatenate with <code>text</code>.</td></tr></tbody></table>

Prints an error to the console and plays a sound.

### print\_chat

`print_chat(text: string[, ...])`

<table><thead><tr><th width="182.60767828800178">Name</th><th width="150">Type</th><th>Description</th></tr></thead><tbody><tr><td><strong>text</strong></td><td><strong><code>string</code></strong></td><td>Text to print into the in-game chat.</td></tr><tr><td><strong>...</strong></td><td><strong><code>any</code></strong></td><td>Optional arguments to concatenate with <code>text</code>.</td></tr></tbody></table>

Prints the text to the in-game chat.

### print\_raw

`print_raw(text: string[, ...])`

<table><thead><tr><th width="176">Name</th><th width="150">Type</th><th>Description</th></tr></thead><tbody><tr><td><strong>text</strong></td><td><strong><code>string</code></strong></td><td>Text to print into the console.</td></tr><tr><td><strong>...</strong></td><td><strong><code>any</code></strong></td><td>Optional arguments to concatenate with <code>text</code>.</td></tr></tbody></table>

Prints the text that can be changed in color by prepending it with `"\a"` followed by the color in the hexadecimal "RRGGBB" format. For example, `"\aFF0000Hi"` will print `"Hi"` in red.

### print\_dev

`print_dev(text: string[, ...])`

<table><thead><tr><th width="150">Name</th><th width="150">Type</th><th width="395.7341676883734">Description</th></tr></thead><tbody><tr><td><strong>text</strong></td><td><strong><code>string</code></strong></td><td>Text to print to into the upper-left console panel.</td></tr><tr><td><strong>...</strong></td><td><strong><code>any</code></strong></td><td>Optional arguments to concatenate with <code>text</code>.</td></tr></tbody></table>

Prints the text into the upper-left console panel.

### tonumber

`tonumber(value: any[, base: number]):` <mark style="color:purple;">`number`</mark>

<table><thead><tr><th width="150">Name</th><th width="150">Type</th><th width="395.7341676883734">Description</th></tr></thead><tbody><tr><td><strong>value</strong></td><td><strong><code>any</code></strong></td><td>The value to convert. Can be a number or string.</td></tr><tr><td><strong>base</strong></td><td><strong><code>number</code></strong></td><td>Optional. The base used in the string. Can be any integer between 2 and 36, inclusive.</td></tr></tbody></table>

Returns the numeric representation of the value with the given base, or <mark style="color:purple;">`nil`</mark> if the conversion failed.

### tostring

`tostring(var: any):` <mark style="color:purple;">`string`</mark>

<table><thead><tr><th width="150">Name</th><th width="150">Type</th><th width="395.7341676883734">Description</th></tr></thead><tbody><tr><td><strong>var</strong></td><td><strong><code>any</code></strong></td><td>The object to be converted to a string.</td></tr></tbody></table>

Returns the string representation of the value.

### type

`type(var: any):` <mark style="color:purple;">`string`</mark>

<table><thead><tr><th width="150">Name</th><th width="150">Type</th><th width="395.7341676883734">Description</th></tr></thead><tbody><tr><td><strong>var</strong></td><td><strong><code>any</code></strong></td><td>The object to get the type of.</td></tr></tbody></table>

Returns the name of the object's type.

### unpack

`unpack(tbl: table, start_index: number, end_index: number):` <mark style="color:purple;">`...`</mark>

<table><thead><tr><th width="150">Name</th><th width="150">Type</th><th width="395.7341676883734">Description</th></tr></thead><tbody><tr><td><strong>tbl</strong></td><td><strong><code>table</code></strong></td><td>The table to generate the vararg from.</td></tr><tr><td><strong>start_index</strong></td><td><strong><code>number</code></strong></td><td>Which index to start from. Optional.</td></tr><tr><td><strong>end_index</strong></td><td><strong><code>number</code></strong></td><td>Which index to end at. Optional, even if you set <code>start_index</code>.</td></tr></tbody></table>

### xpcall

`xpcall(func: function, err_callback: function[, ...]):` <mark style="color:purple;">`boolean`</mark>, <mark style="color:purple;">`...`</mark>

<table><thead><tr><th width="150">Name</th><th width="150">Type</th><th width="395.7341676883734">Description</th></tr></thead><tbody><tr><td><strong>func</strong></td><td><strong><code>function</code></strong></td><td>The function to call initially.</td></tr><tr><td><strong>err_callback</strong></td><td><strong><code>function</code></strong></td><td>The function to be called if execution of the first fails. The error message is passed as a string.</td></tr><tr><td><strong>...</strong></td><td><strong><code>any</code></strong></td><td>Arguments to pass to the initial function.</td></tr></tbody></table>

Attempts to call the first function. If the execution succeeds, this returns <mark style="color:purple;">`true`</mark> followed by the returns of the function. If execution fails, this returns <mark style="color:purple;">`false`</mark> and the second function is called with the error message.

### to\_ticks

`to_ticks(time: number):` <mark style="color:purple;">`number`</mark>

<table><thead><tr><th width="150">Name</th><th width="150">Type</th><th width="395.7341676883734">Description</th></tr></thead><tbody><tr><td><strong>time</strong></td><td><strong><code>number</code></strong></td><td>The seconds to convert to ticks.</td></tr></tbody></table>

Converts time (seconds) to ticks.

### to\_time

`to_time(ticks: number):` <mark style="color:purple;">`number`</mark>

<table><thead><tr><th width="150">Name</th><th width="150">Type</th><th width="395.7341676883734">Description</th></tr></thead><tbody><tr><td><strong>ticks</strong></td><td><strong><code>number</code></strong></td><td>The number of ticks to convert to time.</td></tr></tbody></table>

Converts ticks to time (seconds).

### new\_class

> ℹ️ This class system makes it easier to structure code in complex projects.

`new_class():` <mark style="color:purple;">`metatable`</mark>

Creates the new class.

{% tabs %}
{% tab title="Example1" %}
{% code overflow="wrap" %}

```lua
local ctx = new_class()
    :struct 'struct_one' {
        variable1 = 'test',
        
        some_function = function(self, arg1)
            print(arg1)
            print(string.format('Hello World (%s)', self.variable1))
        end
    }
    
ctx.struct_one:some_function('test')
```

{% endcode %}
{% endtab %}

{% tab title="Example2" %}

> You can also create multiple structs and access one from another.

```lua
local ctx = new_class()
    :struct 'struct_one' {
        variable = 1,

        some_function = function(self)
            print(string.format(
                'variable from struct_two: %d', 
                self.struct_two.variable
            ))
        end
    }
    
    :struct 'struct_two' {
        variable = 2,
        
        some_function = function(self)
            print(string.format(
                'variable from struct_one: %d', 
                self.struct_one.variable
            ))
        end
    }

ctx.struct_two:some_function()
ctx.struct_one:some_function()

print(ctx.struct_one.variable)
```

{% endtab %}
{% endtabs %}
