User Tools

Site Tools


array

Differences

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

Link to this comparison view

Next revision
Previous revision
array [2020/01/17 20:06] – created justinarray [2024/02/17 10:27] (current) justin
Line 2: Line 2:
 ---- ----
  
-An **array** is a scripting data type consisting of a string of characters enclosed by double quotes on each endStrings are typically used to represent message, for example in the [[Display Message]] function, or when referencing an entity name or property name within script. [[placeholder_expression|Placeholder expressions]] can be used within a string as a way to generate dynamic values at game runtime.+An **array** is a scripting data type consisting of a collection or list of valuesYou can iterate through the values in an array using "For" loop, or check if an array contains a certain value using the "contains" operator in a [[conditional expression]].
  
-====Example:==== +====Examples:==== 
-<code lua+<code bauxite
-display_message("Hello world! This is a string.")+array["ITEM_0001", "ITEM_0005", "ITEM_0008"]
 </code> </code>
 +User-defined list of [[item]] IDs (e.g. from which to randomly pick an item for the player).
  
-The above example demonstrates a string passed to the [[Display Message]] function as an argument.+<code bauxite> 
 +group["room_01"
 +</code> 
 +List of all entities in the current [[map]] that belong to the [[groups|group]] named "room_01". The values in this kind of array are of data type [[Entity]].
  
-<WRAP center round info 100%+<code bauxite
-**Note:** Any double quotation marks within a string (excluding the quotation marks used to enclose itmust be escaped with a preceding backslash+entity["xyz"].groups 
-</WRAP>+</code> 
 +List of all [[groups|group]] names to which the entity belongs, as assigned in the [[Map Editor]]. The values in this kind of array are of data type [[String]]. 
 + 
 +<code bauxite> 
 +entity["xyz"].tags 
 +</code> 
 +List of all tags for the entity's model, as assigned in the [[Voxel Editor]]. The values in this kind of array are of data type [[String]]. 
 + 
 +<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). 
 + 
 +=====Functions===== 
 +The following functions can be used to manipulate or retrieve the values in an array. 
 +^Name^Description^ 
 +|push_front(value)|Appends value to the beginning of an array.
 +|push_back(value)|Appends a value to the end of an array.| 
 +|pop_front()|Removes and returns the first value of an array.| 
 +|pop_back()|Removes and returns the last value of an array.| 
 +|insert(index, value)|Inserts a value into an array at the specified index (starting at 0).| 
 +|remove(index)|Removes a value from an array at the specified index (starting at 0).| 
 +|erase(value)|Removes the first occurrence of the specified value from an array.| 
 +|clear()|Removes all values from an array.| 
 +|size()|Returns the number of items in an array.| 
 + 
 +====Examples:==== 
 +<code bauxite> 
 +$my_array.push_front($my_value); 
 +</code> 
 +<code bauxite> 
 +$my_array.push_back($my_value); 
 +</code> 
 +<code bauxite> 
 +$first_value = $my_array.pop_front(); 
 +</code> 
 +<code bauxite> 
 +$last_value = $my_array.pop_back(); 
 +</code> 
 +<code bauxite> 
 +$my_array.insert(1, $my_value); 
 +</code> 
 +<code bauxite> 
 +$my_array.remove(2); 
 +</code> 
 +<code bauxite> 
 +$my_array.erase($my_value); 
 +</code> 
 +<code bauxite> 
 +$my_array.clear(); 
 +</code> 
 +<code bauxite> 
 +$item_count = $my_array.size(); 
 +</code>
  
 ~~NOTOC~~ ~~NOTOC~~
array.1579320376.txt.gz · Last modified: 2020/01/17 20:06 by justin