User Tools

Site Tools


data_files

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
data_files [2020/05/05 12:24] justindata_files [2022/06/26 02:26] justin
Line 14: Line 14:
 </code> </code>
  
-You can then use the "data" syntax to reference the filename (minus the .json extension) and access its data from a [[script]]. In our example, you could use this syntax along with a [[script_syntax|For loop]] to give each [[item]] to the player from your game's [[startup script]].+You can then use the "data" syntax to reference the filename and access its data from a [[script]]. In our example, you could use this syntax along with a [[script_syntax|For loop]] to give each [[item]] to the player from your game's [[startup script]].
  
 <code bauxite> <code bauxite>
-for item_id in data["start_items"] do +for $item_id in data["start_items.json"] do 
-   give_item(item_id) +   give_item($item_id); 
-end+end;
 </code> </code>
  
Line 25: Line 25:
  
 <code bauxite> <code bauxite>
-for i in range(3) do +for $i in range(3) do 
-   give_item(data["start_items"][i]) +   give_item(data["start_items"][$i]); 
-end+end;
 </code> </code>
  
 <code bauxite> <code bauxite>
-give_item(data["start_items"][random(0, 2)])+give_item(data["start_items"][random(0, 2)]);
 </code> </code>
  
Line 52: Line 52:
  
 <code bauxite> <code bauxite>
-for item in data["start_items"] do +for $item in data["start_items"] do 
-  give_item(item["id"], item["count"]) +  give_item($item["id"], $item["count"]); 
-end+end;
 </code> </code>
  
-As another example, assume that we want to maintain a list of [[entity]] properties that will be assigned to a [[character]] at some point during the game. A file named "npc_properties.json" could be created in the data folder with the following contents (specifically an object with a set of key/value pairs as the root element).+As another example, assume that we want to maintain a list of [[entity]] properties that will be assigned to a [[character]] at some point during the game. A file named "npc_props.json" could be created in the data folder with the following contents (specifically an object with a set of key/value pairs as the root element).
  
 <code javascript> <code javascript>
 { {
-   "visited": false+   "visited": false
 +   "visit_count": 0, 
 +   "mood": "happy"
 } }
 </code> </code>
  
-You could then loop through each of the key/value pairs and assign the value to a property on the [[entity]].+You could then loop through the key/value pairs and assign each value to a property on the [[entity]].
  
 <code bauxite> <code bauxite>
-for prop_name in data["npc_properties"] do +for $prop in data["npc_props"] do 
-   set_entity_property(selfprop_name, data["props"][prop_name]) +   set_entity_property(entity["npc01"]$prop, data["npc_props"][$prop]); 
-end+end;
 </code> </code>
  
 ~~NOTOC~~ ~~NOTOC~~
data_files.txt · Last modified: 2022/06/26 02:27 by justin