User Tools

Site Tools


script_syntax

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
script_syntax [2021/04/21 00:30] justinscript_syntax [2023/11/06 14:13] (current) justin
Line 2: Line 2:
 ---- ----
  
-**Bauxite**, the scripting language for RPG in a Box, is a simple imperative language designed specifically for the engine. The syntax for Bauxite is useful to know for creating [[quick script|quick scripts]] for tiles and objects in the [[Map Editor]] or for script nodes in the [[Dialogue Editor]].+**Bauxite**, the scripting language for RPG in a Box, is designed specifically for the engine. The syntax for Bauxite is useful to know for creating [[quick script|quick scripts]] for tiles and objects in the [[Map Editor]] or for script nodes in the [[Dialogue Editor]].
  
 =====Statement Syntax===== =====Statement Syntax=====
Line 12: Line 12:
 **Examples:** **Examples:**
 <code bauxite> <code bauxite>
-display_message("Hello, world!")+display_message("Hello, world!");
 </code> </code>
 <code bauxite> <code bauxite>
 lock_camera(); lock_camera();
 move_camera("cam_position_01"); move_camera("cam_position_01");
-start_dialogue("cutscene_01")+start_dialogue("cutscene_01");
 </code> </code>
  
Line 32: Line 32:
 **Examples:** **Examples:**
 <code bauxite> <code bauxite>
-$rand_num = random(1, 20)+$rand_num = random(1, 20);
 </code> </code>
 <code bauxite> <code bauxite>
-entity["sign_01"].property["message"] = "I am a sign!"+entity["sign_01"].property["message"] = "I am a sign!";
 </code> </code>
 <code bauxite> <code bauxite>
-player.stat["max_hp"] += 5+player.stat["max_hp"] += 5;
 </code> </code>
  
Line 50: Line 50:
 <code bauxite> <code bauxite>
 if global.property["gem_count"] > 5 then if global.property["gem_count"] > 5 then
-   display_message("You've collected more than 5 gems!"+   display_message("You've collected more than 5 gems!"); 
-end+end;
 </code> </code>
 <code bauxite> <code bauxite>
Line 57: Line 57:
    remove_item("ITEM_0001");    remove_item("ITEM_0001");
    display_message("The door is now unlocked!");    display_message("The door is now unlocked!");
-   self.property["locked"] = false+   self.property["locked"] = false;
 else else
-   display_message("You need a gold key to unlock this door."+   display_message("You need a gold key to unlock this door."); 
-end+end;
 </code> </code>
 <code bauxite> <code bauxite>
 $rand_num = random(1, 20); $rand_num = random(1, 20);
 if $rand_num > 15 then if $rand_num > 15 then
-   give_item("ITEM_0001")+   give_item("ITEM_0001");
 elseif $rand_num > 10 then elseif $rand_num > 10 then
-   give_item("ITEM_0002")+   give_item("ITEM_0002");
 else else
-   give_item("ITEM_0003"+   give_item("ITEM_0003"); 
-end+end;
 </code> </code>
  
Line 82: Line 82:
 while global.property["regen_hp"] do while global.property["regen_hp"] do
    player.stat["hp"] += 1;    player.stat["hp"] += 1;
-   wait(2) +   wait(2); 
-end+end;
 </code> </code>
  
Line 93: Line 93:
 display_message("The explosion damages all of the enemies!"); display_message("The explosion damages all of the enemies!");
 for $slime_entity in group["slimes"] do for $slime_entity in group["slimes"] do
-   damage_entity($slime_entity, 5) +   damage_entity($slime_entity, 5); 
-end+end;
 </code> </code>
 Deals 5 damage to each [[entity]] in the "slimes" [[groups|group]]. Deals 5 damage to each [[entity]] in the "slimes" [[groups|group]].
 +<code bauxite>
 +$item_list = array["ITEM_0001", "ITEM_0002", "ITEM_0003"];
 +for $item_id in $item_list do
 +   give_item($item_id);
 +end;
 +</code>
 +Gives one of every item in $item_list to the player by iterating over the entire [[array]].
 <code bauxite> <code bauxite>
 for $i in range(1, 4) do for $i in range(1, 4) do
-   give_item("ITEM_000""${i}", $i) +   give_item("ITEM_000"str($i), $i); 
-end+end;
 </code> </code>
 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/list of values. These values can be stored in variables or properties (see assignment statements above, or [[Set Global Property]] and [[Set Entity Property]]), and can be compared to another value of the same type using a [[conditional expression]].+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/list of values. These values can be stored in variables or properties (see assignment statements above, or [[Set Global Property]] and [[Set Entity Property]]), and can be compared to another value of the same type using a [[conditional expression]].
  
 ^Type^Examples^ ^Type^Examples^
 |[[String]]|"Hello, world!", "This is a string."| |[[String]]|"Hello, world!", "This is a string."|
-|[[Decimal]]|17, 3.14159|+|[[Number]]|17, 3.14159|
 |[[Boolean]]|true, false| |[[Boolean]]|true, false|
 |[[Coordinate]]|coord[1, 2, 3], entity["slime_01"].coord| |[[Coordinate]]|coord[1, 2, 3], entity["slime_01"].coord|
 |[[Color]]|color[255, 0, 255]| |[[Color]]|color[255, 0, 255]|
 |[[Entity]]|player, self, entity["sign"]| |[[Entity]]|player, self, entity["sign"]|
-|[[Array]]|group["room_01"], self.groups|+|[[Array]]|array["A", "B", "C"], group["room_01"], self.groups
 +|[[Codex]]|codex["id": "ITEM_0001", "count": 5]|
 |Null|null| |Null|null|
  
-====Arrays====+====Array====
 An [[array]] is simply a list of values, such as the [[entity|entities]] belonging to a [[groups|group]], the tags assigned to a model, or even a custom set of values defined directly within a [[script]]. Refer to the [[Array]] documentation for more examples, as well as information about the available functions that can be used to manipulate an [[array|array's]] values. An [[array]] is simply a list of values, such as the [[entity|entities]] belonging to a [[groups|group]], the tags assigned to a model, or even a custom set of values defined directly within a [[script]]. Refer to the [[Array]] documentation for more examples, as well as information about the available functions that can be used to manipulate an [[array|array's]] values.
 ^Type^Description^Example^ ^Type^Description^Example^
Line 131: Line 139:
 <code bauxite> <code bauxite>
 for $slime_entity in group["slimes"] do for $slime_entity in group["slimes"] do
-   damage_entity($slime_entity, 2) +   damage_entity($slime_entity, 2); 
-end+end;
 </code> </code>
 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 "human" then if player.tags contains "human" then
-   display_message("No humans allowed!"+   display_message("No humans allowed!"); 
-end+end;
 </code> </code>
 Displays the message if the player model's tag list contains the "human" tag. Displays the message if the player model's tag list contains the "human" tag.
Line 145: Line 153:
 load_map($dungeon_map_list[random(0, 3)], coord[0, 0, 0]); load_map($dungeon_map_list[random(0, 3)], coord[0, 0, 0]);
 $item_list = array["ITEM_0001", "ITEM_0005", "ITEM_0008"]; $item_list = array["ITEM_0001", "ITEM_0005", "ITEM_0008"];
-give_item($item_list[random(0, 2)], 5)+give_item($item_list[random(0, 2)], 5);
 </code> </code>
 Loads a random map from the "dungeon_map_list" array variable ("room1" through "room4"), then gives the player 5 of a random item from the "item_list" array variable. Loads a random map from the "dungeon_map_list" array variable ("room1" through "room4"), then gives the player 5 of a random item from the "item_list" array variable.
 +
 +====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 155: Line 166:
 <code bauxite> <code bauxite>
 if x == null then if x == null then
-   print("Variable x is not yet defined or has no value."+   print("Variable x is not yet defined or has no value."); 
-end+end;
 </code> </code>
 <code bauxite> <code bauxite>
 if entity["some_id"] != null then if entity["some_id"] != null then
-   remove_entity(entity["some_id"]) +   remove_entity(entity["some_id"]); 
-end+end;
 </code> </code>
 <code bauxite> <code bauxite>
Line 167: Line 178:
 $target_tile = tile[7, 8, 0]; $target_tile = tile[7, 8, 0];
 if $target_tile == null then if $target_tile == null then
-   print("Target tile doesn't exist.")+   print("Target tile doesn't exist.");
 else else
-   move_player($target_tile) +   move_player($target_tile); 
-end+end;
 </code> </code>
  
Line 183: Line 194:
 **Examples:** **Examples:**
 <code bauxite> <code bauxite>
-wait(random(1, 5))+wait(random(1, 5));
 </code> </code>
 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 189: Line 200:
 <code bauxite> <code bauxite>
 if random(0, 100) <= 25 then if random(0, 100) <= 25 then
-  give_item("ITEM_0001")+  give_item("ITEM_0001");
 else else
-  give_item("ITEM_0002"+  give_item("ITEM_0002"); 
-end+end;
 </code> </code>
 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, **XdY**, where **X** is the number of dice to roll and **Y** is how many sides the dice have.
 +
 +**Examples:**
 +<code bauxite>
 +$result = 1d20;
 +</code>
 +Gives the result of rolling a twenty-sided die.
 +
 +<code bauxite>
 +$result = 2d8 + 1d6;
 +</code>
 +Gives the result of rolling two eight-sided dice and one six-sided die.
  
 ====Range==== ====Range====
Line 219: Line 244:
 </code> </code>
 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**, the new variable or property will only contain a reference to the original [[codex]], so any changes to one will affect the other (i.e. both "print" statements will display 10).
 +<code bauxite>
 +$items = codex["id": "ITEM_0001", "count": 5];
 +$items_copy = $items;
 +$items_copy["count"] = 10;
 +print($items["count"]);
 +print($items_copy["count"]);
 +</code>
 +
 +In the example below, a copy of **$items** is made using the "Duplicate" function. Since it's now a unique copy of the [[codex]], if the "count" key is changed to 10 for the **$items_copy** variable, the original **$items** [[codex]] will remain unchanged. Therefore, the first "print" statement will display 5, while the second "print" statement will display 10.
 +<code bauxite>
 +$items = codex["id": "ITEM_0001", "count": 5];
 +$items_copy = duplicate($items);
 +$items_copy["count"] = 10;
 +print($items["count"]);
 +print($items_copy["count"]);
 +</code>
  
 ====Inverse==== ====Inverse====
Line 233: Line 279:
 **Examples:** **Examples:**
 <code bauxite> <code bauxite>
-rotate_player_to_direction(inverse(entity["goblin"].direction))+rotate_player_to_direction(inverse(entity["goblin"].direction));
 </code> </code>
 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.
Line 243: Line 289:
 <code bauxite> <code bauxite>
 $counter += 1; $counter += 1;
-$new_tile_id = "tile" + str($counter)+$new_tile_id = "tile" + str($counter);
 </code> </code>
 <code bauxite> <code bauxite>
 $string_with_num = "17"; $string_with_num = "17";
-$new_value = num($string_with_num) + 1+$new_value = num($string_with_num) + 1;
 </code> </code>
  
-~~NOCACHE~~+====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, $num2) begin 
 +   $total = $num1 + $num2; 
 +   return $total; 
 +end; 
 +$result = add_numbers(10, 7); 
 +display_message("Result: " + str($result)); 
 +</code>
 ~~NOTOC~~ ~~NOTOC~~
script_syntax.1618990206.txt.gz · Last modified: 2021/04/21 00:30 by justin