Data Script
The Data script (Scripts/Data.gd) can be used to store data related to the game state. Things like the player's name, event flags, etc. It is a global script, meaning it can be accessed from anywhere in the project by using 'Data.my_variable_name.'
Information should be stored in Data as variables:
var player_name: String = "Stranger";
var my_flag: bool = false;
NOTE: Every variable in the Data script must be of a type that is able to be converted to JSON by JSON.stringify(). This is because the contents of the Data script are converted into a Dictionary and stored as JSON when calling Narrare.save(). For more information on saving, see Narrare.
The Data script comes with a variable and methods related to storing and retrieving a player's inventory. These are defined in the DataBase class, which the Data script extends.
Variables
player_inventory
player_inventory: PackedStringArray;
The player's inventory. Contains a PackedStringArray of identifiers of Interactables which reference Interactables defined in the Interactables script. To add an Interactable to the player's inventory, use add_to_inventory. To remove an item, use remove_from_inventory. You can use get_inventory to access this property.
Note that Interactable in the player's inventory must be stored in the Interactables script, NOT in a Room's
room_interactablesproperty.
Functions
add_to_inventory
add_to_inventory(item_name: String) -> voidAdds an interactable name to the player's inventory.
remove_from_inventory
remove_from_inventory(item_name: String) -> boolRemoves an interactable by name from the player's inventory. Returns
falseif that interactable name wasn't found in the inventory, otherwise returnstrue.
get_inventory
get_inventory() -> PackedStringArrayGets the player's inventory.
to_dict
to_dict() -> DictionaryConverts this script's properties into a
Dictionary. Called when usingNarrare.save().
from_dict
from_dict(in_data_dict: Dictionary) -> voidTakes a
Dictionaryin_data_dictgenerated by to_dict and sets the contents of the Data script to equal the values inin_data_dict. Called when usingNarrare.load().