Is an inventory saved, between games ?
Inventory implementations generally use one or more Story Variables to track whatās in the container, and the current state of the Story Variables is persisted to the History system each time a Passage Transition occurs. And the current state of the History system is persisted in each Save the end-user creates.
So an Inventory is saved whenever the end-user creates a Save, and its reloaded whenever the end-user loads a Save.
It is unclear what you mean by ābetween gamesā, if you mean:
- Between play-throughs of a specific story/game, then the answer would be Yes if the end-user makes Saves.
- Is the current state of the Inventory of one specific story/game automatically available from another specific story/game, then No. Although there are techniques that can be used to transfer data for one story/game to another.
Thanks Greyelf ! So, the variables are saved in the Browser History (not the user hard drive).
Variables are saved with each game save (save slot), and game saves are saved to your browserās localstorage. As you might guess from the name, localstorage is stored locally (as in on your hard drive). So, variables are saved on your hard drive, not in your history thatās synced between browsers.
If youāre asking if you can save the game on one PC and turn load that save on another PC, the answer is no. If thatās what youāre looking for, a work around would be to save the save file using the āsave to diskā option in the save menu, pass the file to your other computer using google drive or something, and then load it using āload from diskā. Kind of clunky but it should work.
Thanks. I am an experienced programmer, but noob to Twine.
Iām trying to create a āzork-likeā inventory, where objects have a location value (in a room, or in inventory). So, if I drop an object in a room, it can still be there when I return.
I did something similar in an unfinished game. What I did was create two object lists: one for rooms and one for objects. That way I always knew what was where.
<<set $rooms = {
office: ["coffee_cup"]
}>>
<<set $items = {
coffee_cup: {
name: "cup of coffee",
location: "office"
}
}>>
etc. And if you have the names of the room the same as the passage name, you can just use a macro to automatically list the stuff in the room.
Or at least thatās how I did it. But maybe you already guessed thatās the easiest way.
I once went a step further and use a single variable to store all ācontainersā in the project, both those that represented each of the ālocationsā as well as the container that represented the āplayerā inventory.
eg. The equivalent of the followingā¦
<<set $containers to {
'player': [],
'office': ['coffee_cup']
}>>
ā¦and if a specific ālocationā name didnāt exist as a property within the $containers
object then that mean there were no items in that ālocationā, as did the array assigned to a ālocationā property being empty.
eg.
<<if not $containers.hasOwnProperty('library') or $containers['library'].length is 0>>
The Library has no items in it.
<</if>>
note: I actually use āfriendlyā functions & macros to handle adding/removing/checking-for items for locations and the player.
Thats a good method, Iāll try it.
FYI, Writing a game is a lot of fun for me. Iām 74 and recently retired from 56 years of business programming.
This game will be the first program Iāve written for myself. Iāve always enjoyed Zork series, and am trying to create a similar adventure game with video, images image maps, and audio.
If youāre interested, you might want to take a look at my Universal Inventory System (UInv). Itās written for use with Twine/SugarCube to try to simplify all of the complexities of creating a decent inventory system. I do note that itās not quite at v1.0 yet, primarily due to needing to finish the documentation, sample code, and the UI tools, but itās perfectly functional for most purposes as it is currently.
It uses a framework where there are ābagsā (things which can contain items) and āitemsā (things which can be added to, removed from, or moved between bags). So, you could set the player and the rooms up as ābagsā with items in them, and then simply transfer those items between the player ābagā and the current roomās ābagā as needed.
Hope that helps, good luck with your game, and donāt get lost in the maze of twisty little passages all alike!
Thanks HiEv,
Looks like youāre well on the way to have a very ācompleteā inventory system.
New Question. I am using the Inventory ok. Is it possible to add an object to the inventory, without linking to another page.
ie.
<<if $inventory.indexOf(āAn Unsigned Noteā) == -1>>There is a note here. [[Pick up An Unsigned Note.]]<>
āand/orā
<<set $inventory.push(āAn Unsigned Noteā, āAn Unsigned Noteā)>>
Yes, there are lots of ways. Did you have any method in particular in mind for how the user would do that?
You might want to check out the āSimple Update Without Reloadā and āSwapping Itemsā examples from my Twine/SugarCube sample code collection to see some examples of things you could do and how to code them.
Iām not sure why you put the same text there twice. Youād only need to do:
<<set $inventory.push("An Unsigned Note")>>
and that would add the string āAn Unsigned Noteā to the end of the $inventory array. (See the .push() method for details.)
Hope that helps!
P.S. When posting code in these forums you should make sure you mark it as āPreformatted textā using the </>
button, otherwise the forum tends to āeatā the inside of some macros. (For example, see how your <</if>>
ended up getting up being displayed as <>.)
Great. Thanks.
Fundamentally I want to do this:
----- Passage -----
As you stroll along the path. . .
You are carrying: Nothing
You see a note. Pickup the Note
----- Same Passage ā
As you stroll along the path. . .
You are carrying: The Note