[Solved] Quest 6 (again) - Storing/retrieving player inventory

This is hopefully my last post asking for help, honest.

I'm trying to store the player's inventory when they run a certain command, clearing out their inventory and then returning it when another command is ran. I can't figure out how, here's what I've tried:

Attempt 1:

			game.player.meatInv = world.INVENTORY
			game.player.INVENTORY = null;

Attempt 2:

			game.player.getContents(world.INVENTORY).forEach(function() {
				this.moveToFrom("invspace", game.player.name);

Okay, this one is complicated, so I made an example game to illustrate (revised, because I forgot assign properName to my rooms):

"use strict"

createItem("me", PLAYER(), {
  examine: "Best. Adventurer. Ever!{once:

(TIP: You can enter INVENTORY to see what you are carrying.)}", hitpoints:100, }) createRoom("lounge", { desc:"The lounge is boring today.", properName: true }) createRoom("nowhere") createItem("red_button", BUTTON(), { desc: "A red button.", loc: "lounge", push: () => { msg("You push it.") msg("The button begins to flash. A siren blares. A police officer appears, seemingly out of nowhere. He aims an odd-looking device at you, and you wake up in . . .") // Create a temporary variable to target everything in the player's inventory. let playerInventory = game.player.getContents(world.ALL) // ^ temp variable // get the inventory ^ // ^ This is 0. (I don't know how this part works.) playerInventory.forEach(item => { // Move each item in the player's inventory to the room called "nowhere" (which is nowhere in the game world). item.moveToFrom("nowhere") // https://github.com/ThePix/QuestJS/wiki/Attributes-for-items#movetofromfromloc-toloc-count }) // Move the player directly to jail. world.setRoom(game.player, "jail_cell", false, true) // there was no direction involved ^ // ^ This move was forced (IMPORTANT)! // // https://github.com/ThePix/QuestJS/wiki/Attributes-for-items#worldsetroomchar-roomname-dir-forced return world.SUCCESS } }) createItem("car_key",{ loc:"me" }) createItem("house_key",{ loc:"me" }) createItem("wallet",{ loc:"me" }) createItem("phone",{ loc:"me" }) createRoom("jail_cell",{ desc: "You are in a tiny cell with no door.", out: new Exit("police_station"), properName: true }) function doOutOfCell(){ let s = `Officer Friendly sees you enter the room and says, "well, now! If it ain't the red button pusher! I see you got some rest!"

He pauses, giving you the hairy eyeball, then continues, "let's just hope we don't find out we've got us an adventurer! Ya' year?"

With that, he reaches underneath his desk, retrieves your stuff, and returns it to you.` msg(s) // Create a temporary variable to target everything that was in the player's inventory (which is currently "nowhere"). let stuff = w.nowhere.getContents(world.ALL) // ^ get all the stuff we moved to "nowhere"! stuff.forEach(item => { // Move each item in the player's inventory to the room called "nowhere" (which is nowhere in the game world). item.moveToFrom(game.player.name) // ^ Make sure this is the name (a string), not the actual object! // If the panes are enabled, this will immediately update the inventory list io.updateUIItems() // https://github.com/ThePix/QuestJS/wiki/Attributes-for-items#movetofromfromloc-toloc-count }) } createRoom("police_station",{ desc: 'You are in a police station.{once:}', // this part will only happen once ^ ^ there is no image, so the 'onerror' will run doOutOfCell() when this prints properName: true, in: new Exit("jail_cell") }) createItem("Officer_Friendly", NPC(false),{ loc: "police_station", properName: true, }) createItem("desk", SURFACE(), { loc: "police_station", scenery: true })

[ You can click this text to see this code in action. ]

Peek 2021-01-04 08-16

Thanks for the help! I'll give this a try.

If this thread seems to disappear, look in the QuestKit forum.

We are planning to use that forum for the Quest 6 stuff until it gets its name changed to the "Quest 6" forum. Quest 5 users might get confused by the Quest 6 code, and Quest 6 hasn't even really been released yet.

I don't want to seem unpleasant at all. It's not a big deal. It's just that Quest 5's code is totally different than that of Quest 6, and Quest 5's main appeal is how easy it is to use with no coding knowledge. (All this JS code might scare some novice Quest 5 users.)


Quest 6 will have an editor which makes it just as easy to use as Quest 5 (if not easier), but it is not ready for release as of writing this.

Here's more Quest-like code for the police station. (Same in-game results.)

  desc: 'You are in a police station.',
  properName: true,
  in: new Exit("jail_cell"),
  afterFirstEnter: () => {

This topic is now closed. Topics are closed after 60 days of inactivity.