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 revision Previous revision
Next revision
Previous revision
script_syntax [2020/02/06 19:45]
justin
script_syntax [2020/02/18 17:38] (current)
justin
Line 87: Line 87:
  
 ====For Loop==== ====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 "​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.+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.
  
-**Example:**+**Examples:**
 <code bauxite> <code bauxite>
 display_message("​The explosion damages all of the enemies!"​);​ display_message("​The explosion damages all of the enemies!"​);​
Line 96: Line 96:
 end end
 </​code>​ </​code>​
 +Deals 5 damage to each [[entity]] in the "​slimes"​ [[groups|group]].
 +<code bauxite>
 +for i in range(1, 4) do
 +   ​give_item("​ITEM_000"​ + "​${i}",​ i)
 +end
 +</​code>​
 +Gives the following items to the player: one of ITEM_0001, two of ITEM_0002, and three of ITEM_0003.
  
 =====Data Types===== =====Data Types=====
Line 108: Line 115:
 |[[Entity]]|player,​ self, entity["​sign"​]| |[[Entity]]|player,​ self, entity["​sign"​]|
 |[[Array]]|group["​room_01"​],​ self.groups| |[[Array]]|group["​room_01"​],​ self.groups|
 +|Null|null|
  
 ====Arrays==== ====Arrays====
-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]].+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.
 ^Type^Description^Example^ ^Type^Description^Example^
 +|User-Defined|List of custom values declared with the "​array"​ syntax.|array["​A",​ "​B",​ "​C"​]|
 +|Range|List of integers based on a set of parameters.|range(1,​ 5)|
 |Entities in a Group|List of all [[entity|entities]] assigned to a map [[groups|group]].|group["​slimes"​],​ group["​trap_tiles"​]| |Entities in a Group|List of all [[entity|entities]] assigned to a map [[groups|group]].|group["​slimes"​],​ group["​trap_tiles"​]|
 |Groups for an Entity|List of all [[groups|group]] to which an [[entity]] belongs.|self.groups,​ entity["​some_id"​].groups| |Groups for an Entity|List of all [[groups|group]] to which an [[entity]] belongs.|self.groups,​ entity["​some_id"​].groups|
 |Tags for an Entity|List of tags assigned to an [[entity|entity'​s]] model (see [[Model Properties]]).|player.tags,​ initiator.tags| |Tags for an Entity|List of tags assigned to an [[entity|entity'​s]] model (see [[Model Properties]]).|player.tags,​ initiator.tags|
-|User-Defined|List of custom values declared with the "​array"​ syntax.|array["​A",​ "​B",​ "​C"​]| 
  
-The values in an array can be iterated through using a "​For"​ loop. You can also check to see if a particular ​value exists ​within ​an array using the "contains" ​operator in a [[conditional expression]]. See below for some example script usages.+The values in an [[array]] can be iterated through using a "​For"​ loop, or you can get the value at a specific position ​within ​the [[array]] using the index syntax //​my_array[x]//,​ where "my_array" ​is an [[array]] variable and "​x"​ is an integer ranging from 0 to one less than the [[array]] size. See below for some example ​[[script]] usages.
  
 **Examples:​** **Examples:​**
Line 125: Line 134:
 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
Line 138: Line 147:
 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. 
 + 
 +====Null==== 
 +The "​null"​ keyword represents the absence of a value. It can be used to check whether or not a variable has been assigned a value yet, or if a reference to an entity is valid. 
 + 
 +**Examples:​** 
 +<code bauxite>​ 
 +if x == null then 
 +   ​print("​Variable x is not yet defined or has no value."​) 
 +end 
 +</​code>​ 
 +<code bauxite>​ 
 +if entity["​some_id"​] != null then 
 +   ​remove_entity(entity["​some_id"​]) 
 +end 
 +</​code>​ 
 +<code bauxite>​ 
 +set_player_movement_locked(true);​ 
 +target_tile = tile[7, 8, 0]; 
 +if target_tile == null then 
 +   ​print("​Target tile doesn'​t exist."​) 
 +else 
 +   ​move_player(target_tile) 
 +end 
 +</​code>​
  
 =====Functions===== =====Functions=====
Line 162: Line 195:
 </​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.
 +
 +====Range====
 +The **range** function generates an [[array]] of integers based on the supplied parameters. With one parameter, say "​a",​ it generates a list starting with 0 and ending with one less than "​a"​. With two parameters, say "​a"​ and "​b",​ it generates a list starting with "​a"​ and ending with one less than "​b"​. With three parameters, say "​a",​ "​b",​ and "​c",​ it generates a list starting with "​a",​ incrementing by "​c",​ and ending before "​b"​ is reached. ​ See below for some examples of each scenario.
 +
 +**Examples:​**
 +<code bauxite>
 +range(5)
 +</​code>​
 +List of integers from 0 to, but not including, 5 (i.e. 0, 1, 2, 3, 4).
 +
 +<code bauxite>
 +range(12, 15)
 +</​code>​
 +List of integers from 12 to, but not including, 15 (i.e. 12, 13, 14).
 +
 +<code bauxite>
 +range(0, 9, 2)
 +</​code>​
 +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)
 +</​code>​
 +List of integers from 5 to, but not including, 0, with an increment of -1 (i.e. 5, 4, 3, 2, 1).
  
 ====Inverse==== ====Inverse====
script_syntax.1581047120.txt.gz · Last modified: 2020/02/06 19:45 by justin