This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| script_syntax [2021/05/05 12:37] – justin | script_syntax [2023/11/06 14:13] (current) – justin | ||
|---|---|---|---|
| Line 2: | Line 2: | ||
| ---- | ---- | ||
| - | **Bauxite**, | + | **Bauxite**, |
| =====Statement Syntax===== | =====Statement Syntax===== | ||
| Line 112: | Line 112: | ||
| =====Data Types===== | =====Data Types===== | ||
| - | There are several data types available in the scripting language used to represent a value or, in the case of arrays, a collection/ | + | There are several data types available in the scripting language used to represent a value or, in the case of an array or codex, a collection/ |
| ^Type^Examples^ | ^Type^Examples^ | ||
| |[[String]]|" | |[[String]]|" | ||
| - | |[[Decimal]]|17, 3.14159| | + | |[[Number]]|17, 3.14159| |
| |[[Boolean]]|true, | |[[Boolean]]|true, | ||
| |[[Coordinate]]|coord[1, | |[[Coordinate]]|coord[1, | ||
| |[[Color]]|color[255, | |[[Color]]|color[255, | ||
| |[[Entity]]|player, | |[[Entity]]|player, | ||
| - | |[[Array]]|group[" | + | |[[Array]]|array[" |
| + | |[[Codex]]|codex[" | ||
| |Null|null| | |Null|null| | ||
| - | ====Arrays==== | + | ====Array==== |
| An [[array]] is simply a list of values, such as the [[entity|entities]] belonging to a [[groups|group]], | An [[array]] is simply a list of values, such as the [[entity|entities]] belonging to a [[groups|group]], | ||
| ^Type^Description^Example^ | ^Type^Description^Example^ | ||
| Line 155: | Line 156: | ||
| </ | </ | ||
| Loads a random map from the " | Loads a random map from the " | ||
| + | |||
| + | ====Codex==== | ||
| + | A [[codex]] is a data type with its data stored as key/value pairs. The key is a unique [[string]] and acts as a lookup for its corresponding value within the codex, similar to a dictionary. See [[Codex]] for more information and some scripting examples. | ||
| ====Null==== | ====Null==== | ||
| Line 202: | Line 206: | ||
| </ | </ | ||
| Gives either ITEM_0001 or ITEM_0002 to the player, with a 25% chance that the item will be ITEM_0001. | Gives either ITEM_0001 or ITEM_0002 to the player, with a 25% chance that the item will be ITEM_0001. | ||
| + | |||
| + | ====Dice Rolls==== | ||
| + | Bauxite also supports a dice notation similar to that of Dungeons & Dragons for generating random numbers. Specifically, | ||
| + | |||
| + | **Examples: | ||
| + | <code bauxite> | ||
| + | $result = 1d20; | ||
| + | </ | ||
| + | Gives the result of rolling a twenty-sided die. | ||
| + | |||
| + | <code bauxite> | ||
| + | $result = 2d8 + 1d6; | ||
| + | </ | ||
| + | Gives the result of rolling two eight-sided dice and one six-sided die. | ||
| ====Range==== | ====Range==== | ||
| Line 226: | Line 244: | ||
| </ | </ | ||
| List of integers from 5 to, but not including, 0, with an increment of -1 (i.e. 5, 4, 3, 2, 1). | List of integers from 5 to, but not including, 0, with an increment of -1 (i.e. 5, 4, 3, 2, 1). | ||
| + | |||
| + | ====Duplicate==== | ||
| + | The **duplicate** function creates a unique copy of an [[array]] or [[codex]]. Since the copy is unique, you can modify its data without affecting the original [[array]] or [[codex]]. | ||
| + | |||
| + | With the code below where the value in **$items** is simply stored into another variable, in this case **$items_copy**, | ||
| + | <code bauxite> | ||
| + | $items = codex[" | ||
| + | $items_copy = $items; | ||
| + | $items_copy[" | ||
| + | print($items[" | ||
| + | print($items_copy[" | ||
| + | </ | ||
| + | |||
| + | In the example below, a copy of **$items** is made using the " | ||
| + | <code bauxite> | ||
| + | $items = codex[" | ||
| + | $items_copy = duplicate($items); | ||
| + | $items_copy[" | ||
| + | print($items[" | ||
| + | print($items_copy[" | ||
| + | </ | ||
| ====Inverse==== | ====Inverse==== | ||
| Line 257: | Line 296: | ||
| </ | </ | ||
| + | ====Math Functions==== | ||
| + | ^Name^Description^Example^ | ||
| + | |round(x)|Rounds x to the nearest whole number.|round(16.8) will return 17| | ||
| + | |mod(x, y)|Gives the remainder of x divided by y.|mod(8, 3) will return 2| | ||
| + | |pow(x, y)|Gives the result of x raised to the power of y.|pow(2, 5) will return 32| | ||
| + | |sqrt(x)|Gives the square root of x.|sqrt(16) will return 4| | ||
| + | |abs(x)|Gives the absolute value of x.|abs(-17) will return 17| | ||
| + | |floor(x)|Rounds x downwards to the nearest whole number.|floor(17.7) will return 17| | ||
| + | |ceil(x)|Rounds x upwards to the nearest whole number.|ceil(16.2) will return 17| | ||
| + | |||
| + | ====Custom Functions==== | ||
| + | Custom functions provide a way to define reusable logic that can be called later in the same [[script]]. Custom functions can optionally include input arguments that values are passed into (e.g. the way a map name is passed as a [[string]] into the built-in [[Load Map]] function). They can also optionally return a value to the calling code. Refer to the code below for an example of a custom function that takes two input arguments, adds them together, then returns the total. | ||
| + | |||
| + | **Example: | ||
| + | <code bauxite> | ||
| + | function add_numbers($num1, | ||
| + | | ||
| + | | ||
| + | end; | ||
| + | $result = add_numbers(10, | ||
| + | display_message(" | ||
| + | </ | ||
| ~~NOTOC~~ | ~~NOTOC~~ | ||