This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision | ||
script_syntax [2017/10/17 13:55] – justin | script_syntax [2020/08/05 21:36] – justin | ||
---|---|---|---|
Line 2: | Line 2: | ||
---- | ---- | ||
- | The scripting language | + | **Bauxite**, |
- | =====Statements====== | + | =====Statement Syntax===== |
- | Statements are the basic building blocks of the scripting language and represent a particular action to be taken. | + | Statements are the basic building blocks of the scripting language and represent a particular action to be taken. |
- | ====Function Calls==== | + | =====Function Calls===== |
Calling a function instructs the game to execute some piece of logic, for example to display a message to the player or to move the camera to a specific location. See [[Scripting Reference]] for a comprehensive list of built-in functions that can be called. | Calling a function instructs the game to execute some piece of logic, for example to display a message to the player or to move the camera to a specific location. See [[Scripting Reference]] for a comprehensive list of built-in functions that can be called. | ||
**Examples: | **Examples: | ||
- | < | + | < |
- | display_message(" | + | display_message(" |
</ | </ | ||
- | < | + | < |
lock_camera(); | lock_camera(); | ||
move_camera(" | move_camera(" | ||
Line 20: | Line 20: | ||
</ | </ | ||
- | ====If/ | + | =====Assignment Statements===== |
- | The "if/then/else/end" | + | Assignment statements allow you to assign values to variables, properties, stats, etc. You can use the "=" operator to place a value directly into a variable or, when working with numeric values, one of the four compound operators to first perform a calculation and then place the resulting value back into variable. |
+ | |||
+ | ^Operator^Description^ | ||
+ | |=|Places the value on the right-hand side into the variable on the left-hand side.| | ||
+ | |+=|Adds the value on the right-hand side to the current value of the variable on the left-hand side, then places the resulting value back into the variable.| | ||
+ | |-=|Subtracts the value on the right-hand side from the current value of the variable on the left-hand side, then places the resulting value back into the variable.| | ||
+ | |*=|Multiplies the value on the right-hand side by the current value of the variable on the left-hand side, then places the resulting value back into the variable.| | ||
+ | |/=|Divides the value on the right-hand side by the current value of the variable on the left-hand side, then places the resulting value back into the variable.| | ||
+ | |||
+ | **Examples: | ||
+ | <code bauxite> | ||
+ | $rand_num = random(1, 20) | ||
+ | </code> | ||
+ | <code bauxite> | ||
+ | entity[" | ||
+ | </code> | ||
+ | <code bauxite> | ||
+ | player.stat["max_hp" | ||
+ | </ | ||
+ | |||
+ | =====Control Statements===== | ||
+ | Control statements affect the flow of your script, either by branching or looping through a set of statements multiple times. These include " | ||
+ | |||
+ | ====If Statement==== | ||
+ | If statements | ||
**Examples: | **Examples: | ||
- | < | + | < |
if global.property[" | if global.property[" | ||
| | ||
end | end | ||
</ | </ | ||
- | < | + | < |
- | if player.inventory contains "Gold Key" then | + | if player.inventory contains "ITEM_0001" then |
- | | + | |
| | ||
- | set_entity_property(self, " | + | self.property[" |
else | else | ||
| | ||
+ | end | ||
+ | </ | ||
+ | <code bauxite> | ||
+ | $rand_num = random(1, 20); | ||
+ | if $rand_num > 15 then | ||
+ | | ||
+ | elseif $rand_num > 10 then | ||
+ | | ||
+ | else | ||
+ | | ||
end | end | ||
</ | </ | ||
- | =====Literals===== | + | ====While Loop==== |
- | A literal represents | + | While loops allow you to execute a set of statements repeatedly as long as a particular condition evaluates to true. In the order listed, it consists of the keyword " |
+ | |||
+ | **Example: | ||
+ | <code bauxite> | ||
+ | display_message(" | ||
+ | global.property[" | ||
+ | while global.property[" | ||
+ | | ||
+ | wait(2) | ||
+ | end | ||
+ | </ | ||
+ | |||
+ | ====For Loop==== | ||
+ | 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 " | ||
+ | |||
+ | **Examples: | ||
+ | <code bauxite> | ||
+ | display_message(" | ||
+ | for $slime_entity in group[" | ||
+ | | ||
+ | end | ||
+ | </ | ||
+ | Deals 5 damage to each [[entity]] in the " | ||
+ | <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. | ||
+ | |||
+ | =====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/ | ||
^Type^Examples^ | ^Type^Examples^ | ||
- | |[[String]]|" | + | |[[String]]|" |
|[[Decimal]]|17, | |[[Decimal]]|17, | ||
|[[Boolean]]|true, | |[[Boolean]]|true, | ||
+ | |[[Coordinate]]|coord[1, | ||
+ | |[[Color]]|color[255, | ||
+ | |[[Entity]]|player, | ||
+ | |[[Array]]|group[" | ||
+ | |Null|null| | ||
+ | ====Arrays==== | ||
+ | An [[array]] is simply a list of values, such as the [[entity|entities]] belonging to a [[groups|group]], | ||
+ | ^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[" | ||
+ | |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' | ||
+ | |||
+ | The values in an [[array]] can be iterated through using a " | ||
+ | |||
+ | **Examples: | ||
+ | <code bauxite> | ||
+ | for $slime_entity in group[" | ||
+ | | ||
+ | end | ||
+ | </ | ||
+ | Deals 2 damage to all entities in the " | ||
+ | <code bauxite> | ||
+ | if player.tags contains " | ||
+ | | ||
+ | end | ||
+ | </ | ||
+ | Displays the message if the player model' | ||
+ | <code bauxite> | ||
+ | $dungeon_map_list = array[" | ||
+ | load_map($dungeon_map_list[random(0, | ||
+ | $item_list = array[" | ||
+ | give_item($item_list[random(0, | ||
+ | </ | ||
+ | Loads a random map from the " | ||
+ | |||
+ | ====Null==== | ||
+ | The " | ||
+ | |||
+ | **Examples: | ||
+ | <code bauxite> | ||
+ | if x == null then | ||
+ | | ||
+ | end | ||
+ | </ | ||
+ | <code bauxite> | ||
+ | if entity[" | ||
+ | | ||
+ | end | ||
+ | </ | ||
+ | <code bauxite> | ||
+ | set_player_movement_locked(true); | ||
+ | $target_tile = tile[7, 8, 0]; | ||
+ | if $target_tile == null then | ||
+ | | ||
+ | else | ||
+ | | ||
+ | end | ||
+ | </ | ||
+ | |||
+ | =====Functions===== | ||
+ | |||
+ | ====Action Functions==== | ||
+ | Action functions are used to trigger certain actions or events in your game, such as loading a map, playing an animation, or healing a character. These functions allow you to control the flow of your game and help give life to its world! A full list of the available functions can be found on the [[scripting reference]] page. | ||
+ | |||
+ | ====Random Number==== | ||
+ | The **random number** function generates an integer value within the given range (inclusive of the minimum and maximum value). It can be used in scripts anywhere a numeric value is expected or allowed. | ||
+ | |||
+ | **Examples: | ||
+ | <code bauxite> | ||
+ | wait(random(1, | ||
+ | </ | ||
+ | Waits for a random amount of time between 1 and 5 seconds. | ||
+ | |||
+ | <code bauxite> | ||
+ | if random(0, 100) <= 25 then | ||
+ | give_item(" | ||
+ | else | ||
+ | give_item(" | ||
+ | end | ||
+ | </ | ||
+ | Gives either ITEM_0001 or ITEM_0002 to the player, with a 25% chance that the item will be ITEM_0001. | ||
+ | |||
+ | ====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). | ||
+ | |||
+ | ====Inverse==== | ||
+ | The **inverse** function returns the inverse, or opposite, of a value. It can be used in scripts anywhere a value of the original type is expected or allowed. Refer to the table below for a list of the supported data types and examples of resulting values. | ||
+ | |||
+ | ^Type^Example^ | ||
+ | |[[Number]]|inverse(17) will return -17| | ||
+ | |[[Boolean]]|inverse(true) will return false| | ||
+ | |[[Coordinate]]|inverse(coord[-3, | ||
+ | |[[Color]]|inverse(color[128, | ||
+ | |[[Cardinal Direction]]|inverse(NORTH) will return SOUTH| | ||
+ | |[[navigation_and_interaction|Navigation Type]]|inverse(WALK_AND_INTERACT) will return PENDING| | ||
+ | |||
+ | **Examples: | ||
+ | <code bauxite> | ||
+ | rotate_player_to_direction(inverse(entity[" | ||
+ | </ | ||
+ | Rotates the player character to be facing in the opposite direction that the goblin is facing. | ||
~~NOTOC~~ | ~~NOTOC~~ |