This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionLast revisionBoth sides next revision | ||
script_syntax [2020/02/16 20:54] – justin | script_syntax [2023/11/06 14:11] – justin | ||
---|---|---|---|
Line 2: | Line 2: | ||
---- | ---- | ||
- | The scripting language | + | **Bauxite**, |
=====Statement Syntax===== | =====Statement Syntax===== | ||
- | Statements are the basic building blocks of the scripting language | + | Statements are the basic building blocks of Bauxite |
=====Function Calls===== | =====Function Calls===== | ||
Line 12: | Line 12: | ||
**Examples: | **Examples: | ||
<code bauxite> | <code bauxite> | ||
- | display_message(" | + | display_message(" |
</ | </ | ||
<code bauxite> | <code bauxite> | ||
lock_camera(); | lock_camera(); | ||
move_camera(" | move_camera(" | ||
- | start_dialogue(" | + | start_dialogue(" |
</ | </ | ||
Line 32: | Line 32: | ||
**Examples: | **Examples: | ||
<code bauxite> | <code bauxite> | ||
- | rand_num = random(1, 20) | + | $rand_num = random(1, 20); |
</ | </ | ||
<code bauxite> | <code bauxite> | ||
- | entity[" | + | entity[" |
</ | </ | ||
<code bauxite> | <code bauxite> | ||
- | player.stat[" | + | player.stat[" |
</ | </ | ||
Line 50: | Line 50: | ||
<code bauxite> | <code bauxite> | ||
if global.property[" | if global.property[" | ||
- | | + | |
- | end | + | end; |
</ | </ | ||
<code bauxite> | <code bauxite> | ||
Line 57: | Line 57: | ||
| | ||
| | ||
- | | + | |
else | else | ||
- | | + | |
- | end | + | end; |
</ | </ | ||
<code bauxite> | <code bauxite> | ||
- | rand_num = random(1, 20); | + | $rand_num = random(1, 20); |
- | if rand_num > 15 then | + | if $rand_num > 15 then |
- | | + | |
- | elseif rand_num > 10 then | + | elseif |
- | | + | |
else | else | ||
- | | + | |
- | end | + | end; |
</ | </ | ||
Line 82: | Line 82: | ||
while global.property[" | while global.property[" | ||
| | ||
- | | + | |
- | end | + | end; |
</ | </ | ||
Line 89: | Line 89: | ||
For loops allow you execute a set of statements a given number of times based on an iterable expression (e.g. an [[array]] of values). In the order listed, it consists of the keyword " | For loops allow you execute a set of statements a given number of times based on an iterable expression (e.g. an [[array]] of values). In the order listed, it consists of the keyword " | ||
- | **Example:** | + | **Examples:** |
<code bauxite> | <code bauxite> | ||
display_message(" | display_message(" | ||
- | for slime_entity in group[" | + | for $slime_entity in group[" |
- | | + | |
- | end | + | end; |
</ | </ | ||
Deals 5 damage to each [[entity]] in the " | Deals 5 damage to each [[entity]] in the " | ||
<code bauxite> | <code bauxite> | ||
- | for i in range(1, 4) do | + | $item_list = array[" |
- | | + | for $item_id in $item_list do |
- | end | + | |
+ | end; | ||
+ | </ | ||
+ | Gives one of every item in $item_list to the player by iterating over the entire [[array]]. | ||
+ | <code bauxite> | ||
+ | for $i in range(1, 4) do | ||
+ | | ||
+ | end; | ||
</ | </ | ||
- | Gives the following items to the player: one of "ITEM_0001", two of "ITEM_0002", and three of "ITEM_0003". | + | Gives the following items to the player: one of ITEM_0001, two of ITEM_0002, and three of ITEM_0003. |
=====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^ | ||
+ | |User-Defined|List of custom values declared with the " | ||
+ | |Range|List of integers based on a set of parameters.|range(1, | ||
|Entities in a Group|List of all [[entity|entities]] assigned to a map [[groups|group]].|group[" | |Entities in a Group|List of all [[entity|entities]] assigned to a map [[groups|group]].|group[" | ||
|Groups for an Entity|List of all [[groups|group]] to which an [[entity]] belongs.|self.groups, | |Groups for an Entity|List of all [[groups|group]] to which an [[entity]] belongs.|self.groups, | ||
|Tags for an Entity|List of tags assigned to an [[entity|entity' | |Tags for an Entity|List of tags assigned to an [[entity|entity' | ||
- | |User-Defined|List of custom values declared with the " | ||
- | The values in an array can be iterated through using a " | + | The values in an [[array]] can be iterated through using a " |
**Examples: | **Examples: | ||
<code bauxite> | <code bauxite> | ||
- | for slime_entity in group[" | + | for $slime_entity in group[" |
- | | + | |
- | end | + | end; |
</ | </ | ||
- | Deals 2 damage to all entities in the "Slimes" [[groups|group]]. | + | Deals 2 damage to all entities in the "slimes" [[groups|group]]. |
<code bauxite> | <code bauxite> | ||
if player.tags contains " | if player.tags contains " | ||
- | | + | |
- | end | + | end; |
</ | </ | ||
Displays the message if the player model' | Displays the message if the player model' | ||
<code bauxite> | <code bauxite> | ||
- | dungeon_map_list = array[" | + | $dungeon_map_list = array[" |
- | load_map(dungeon_map_list[random(0, | + | load_map($dungeon_map_list[random(0, |
- | item_list = array[" | + | $item_list = array[" |
- | give_item(item_list[random(0, | + | give_item($item_list[random(0, |
</ | </ | ||
- | 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 154: | Line 166: | ||
<code bauxite> | <code bauxite> | ||
if x == null then | if x == null then | ||
- | | + | |
- | end | + | end; |
</ | </ | ||
<code bauxite> | <code bauxite> | ||
if entity[" | if entity[" | ||
- | | + | |
- | end | + | end; |
</ | </ | ||
<code bauxite> | <code bauxite> | ||
set_player_movement_locked(true); | set_player_movement_locked(true); | ||
- | target_tile = tile[7, 8, 0]; | + | $target_tile = tile[7, 8, 0]; |
- | if target_tile == null then | + | if $target_tile == null then |
- | | + | |
else | else | ||
- | | + | |
- | end | + | end; |
</ | </ | ||
Line 182: | Line 194: | ||
**Examples: | **Examples: | ||
<code bauxite> | <code bauxite> | ||
- | wait(random(1, | + | wait(random(1, |
</ | </ | ||
Waits for a random amount of time between 1 and 5 seconds. | Waits for a random amount of time between 1 and 5 seconds. | ||
Line 188: | Line 200: | ||
<code bauxite> | <code bauxite> | ||
if random(0, 100) <= 25 then | if random(0, 100) <= 25 then | ||
- | give_item(" | + | give_item(" |
else | else | ||
- | give_item(" | + | give_item(" |
- | end | + | end; |
</ | </ | ||
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==== | ||
+ | In addition to the random number function, Bauxite also supports a dice notation similar to that of Dungeons & Dragons. Specifically, | ||
+ | |||
+ | **Examples: | ||
+ | <code bauxite> | ||
+ | $result = 1d6; | ||
+ | </ | ||
+ | Gives the result of rolling one six-sided die. | ||
+ | |||
+ | <code bauxite> | ||
+ | $result = 2d8 + 5; | ||
+ | </ | ||
+ | Gives the result of rolling two eight-sided dice, adding them together, then adding 5 to the total. | ||
+ | |||
+ | ====Range==== | ||
+ | The **range** function generates an [[array]] of integers based on the supplied parameters. With one parameter, say " | ||
+ | |||
+ | **Examples: | ||
+ | <code bauxite> | ||
+ | range(5) | ||
+ | </ | ||
+ | List of integers from 0 to, but not including, 5 (i.e. 0, 1, 2, 3, 4). | ||
+ | |||
+ | <code bauxite> | ||
+ | range(12, 15) | ||
+ | </ | ||
+ | List of integers from 12 to, but not including, 15 (i.e. 12, 13, 14). | ||
+ | |||
+ | <code bauxite> | ||
+ | range(0, 9, 2) | ||
+ | </ | ||
+ | List of integers from 0 to, but not including, 9, with an increment of 2 (i.e. 0, 2, 4, 6, 8). | ||
+ | |||
+ | <code bauxite> | ||
+ | range(5, 0, -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 208: | Line 279: | ||
**Examples: | **Examples: | ||
<code bauxite> | <code bauxite> | ||
- | rotate_player_to_direction(inverse(entity[" | + | rotate_player_to_direction(inverse(entity[" |
</ | </ | ||
Rotates the player character to be facing in the opposite direction that the goblin is facing. | Rotates the player character to be facing in the opposite direction that the goblin is facing. | ||
+ | ====String/ | ||
+ | There are two functions available for converting between a [[string]] and a [[number]]: **str** and **num**. When a variable or property is known to contain a numeric value and you need to concatenate it with a [[string]], you must first convert the [[number]] to a [[string]] using the **str** function. Similarly, if you have a [[string]] and you know it contains a valid numeric value, you can convert it to a [[number]] for use in arithmetic expressions using the **num** function. | ||
+ | |||
+ | **Examples: | ||
+ | <code bauxite> | ||
+ | $counter += 1; | ||
+ | $new_tile_id = " | ||
+ | </ | ||
+ | <code bauxite> | ||
+ | $string_with_num = " | ||
+ | $new_value = num($string_with_num) + 1; | ||
+ | </ | ||
+ | |||
+ | ====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~~ |