This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionLast revisionBoth sides next revision | ||
data_files [2020/05/05 12:05] – justin | data_files [2022/06/26 02:26] – justin | ||
---|---|---|---|
Line 2: | Line 2: | ||
---- | ---- | ||
- | Although it should be considered an experimental feature at this time and requires a bit of manual setup, it's possible to access custom data stored in JSON files from [[script|scripts]]. To do so, you must first create a subfolder named " | + | Although it requires a bit of manual setup, it's possible to access custom data stored in JSON files from [[script|scripts]]. To do so, you must first create a subfolder named " |
As a simple example, let's say you wanted to maintain a list of [[item|items]] that the [[player character]] should begin the game with without needing to update your game's [[startup script]] every time the list changes. In this scenario, you could create a JSON file within the data folder named " | As a simple example, let's say you wanted to maintain a list of [[item|items]] that the [[player character]] should begin the game with without needing to update your game's [[startup script]] every time the list changes. In this scenario, you could create a JSON file within the data folder named " | ||
Line 14: | Line 14: | ||
</ | </ | ||
- | You can then use the " | + | You can then use the " |
<code bauxite> | <code bauxite> | ||
- | for item_id in data[" | + | for $item_id in data[" |
- | | + | |
- | end | + | end; |
</ | </ | ||
- | Alternatively, | + | Alternatively, |
<code bauxite> | <code bauxite> | ||
- | for i in range(3) do | + | for $i in range(3) do |
- | | + | |
- | end | + | end; |
+ | </ | ||
+ | |||
+ | <code bauxite> | ||
+ | give_item(data[" | ||
</ | </ | ||
Line 48: | Line 52: | ||
<code bauxite> | <code bauxite> | ||
- | for item in data[" | + | for $item in data[" |
- | give_item(item[" | + | give_item($item[" |
- | end | + | end; |
</ | </ | ||
+ | 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 " | ||
+ | |||
+ | <code javascript> | ||
+ | { | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | You could then loop through the key/value pairs and assign each value to a property on the [[entity]]. | ||
+ | |||
+ | <code bauxite> | ||
+ | for $prop in data[" | ||
+ | | ||
+ | end; | ||
+ | </ | ||
~~NOTOC~~ | ~~NOTOC~~ |