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
Next revisionBoth sides next revision
script_syntax [2020/01/19 18:30] justinscript_syntax [2020/01/20 19:30] justin
Line 2: Line 2:
 ---- ----
  
-The scripting language in RPG in a Box is a simple imperative language designed specifically for the engine. It is loosely based on the language described [[https://jayconrod.com/posts/37/a-simple-interpreter-from-scratch-in-python-part-1|here]] in the series of articles by Jay Conrod. The syntax 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]].+The scripting language in RPG in a Box is a simple imperative language designed specifically for the engine. The syntax 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 18: Line 18:
 move_camera("cam_position_01"); move_camera("cam_position_01");
 start_dialogue("cutscene_01") start_dialogue("cutscene_01")
 +</code>
 +
 +=====Assignment Statements=====
 +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 freebasic>
 +rand_num = random(1, 20)
 +</code>
 +<code lua>
 +entity["sign_01"].property["message"] = "I am a sign!"
 +</code>
 +<code lua>
 +player.stat["max_hp"] += 5
 </code> </code>
  
Line 24: Line 45:
  
 ====If Statement==== ====If Statement====
-**If statements** allow you to branch your logic according to the results of a condition being evaluated. In the order listed, it consists of the keyword "if", a condition to check, the "then" keyword, any statements to execute if the condition is true, optionally the "else" keyword followed by any statements to execute if the condition is not true, and lastly the "end" keyword. See [[Conditional Expression]] for more information and a list of valid comparison operators that can be used in the condition.+If statements allow you to branch your logic according to the results of a condition being evaluated. In the order listed, it consists of the keyword "if", a condition to check, the "then" keyword, any statements to execute if the condition is true, optionally the "else" keyword followed by any statements to execute if the condition is not true, and lastly the "end" keyword. See [[Conditional Expression]] for more information and a list of valid comparison operators that can be used in the condition.
  
 **Examples:** **Examples:**
Line 34: Line 55:
 <code lua> <code lua>
 if player.inventory contains "ITEM_0001" then if player.inventory contains "ITEM_0001" then
-   remove_item("Gold Key");+   remove_item("ITEM_0001");
    display_message("The door is now unlocked!");    display_message("The door is now unlocked!");
    set_entity_property(self, "locked", false)    set_entity_property(self, "locked", false)
Line 43: Line 64:
  
 ====While Loop==== ====While Loop====
-**While loops**+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 "while", a condition to check, the "do" keyword, any statements to execute if the condition is true, and lastly the "end" keyword. See [[Conditional Expression]] for more information and a list of valid comparison operators that can be used in the condition. 
 + 
 +**Example:** 
 +<code lua> 
 +display_message("You entered a pool of regeneration!"); 
 +global.property["regen_hp"] = true; 
 +while global.property["regen_hp"] do 
 +   player.stat["hp"] += 1; 
 +   wait(2) 
 +end 
 +</code>
  
 ====For Loop==== ====For Loop====
-**For loops**+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", a variable name that the current value will be assigned to, the "in" keyword, an expression to iterate though, the "do" keyword, any number of statements to execute, and lastly the "end" keyword. As [[array]] functionality is still in development, there are currently only a small number of uses cases for "For" loops. 
 + 
 +**Example:** 
 +<code freebasic> 
 +display_message("The explosion damages all of the enemies!"); 
 +for slime_entity in group["slimes"] do 
 +   damage_entity(slime_entity, 5) 
 +end 
 +</code>
  
-=====Literals===== +=====Data Types===== 
-A literal represents an explicit, fixed value. Literals can be stored in properties (see [[Set Global Property]] and [[Set Entity Property]]) or compared to another value of the same type within a [[conditional expression]].+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 valuesThese 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^
Line 55: Line 94:
 |[[Decimal]]|17, 3.14159| |[[Decimal]]|17, 3.14159|
 |[[Boolean]]|true, false| |[[Boolean]]|true, false|
 +|[[Coordinate]]|coord[1, 2, 3], entity["slime_01"].coord|
 +|[[Color]]|color[255, 0, 255]|
 +|[[Entity]]|player, self, entity["sign"]|
 +|[[Array]]|group["room_01"], self.groups|
  
  
 ~~NOTOC~~ ~~NOTOC~~
script_syntax.txt · Last modified: 2023/11/06 14:13 by justin