QuestJS - placing object in container in order and update examine

Hi,

I'm starting a game in QuestJS and it seems I can use straight JS as well as the built-in definitions. I am trying to create a container that can only accept four items and can only accept them when they are placed in order. If one or more of the items has been placed in the container, the examine description should include this. So far I have the following code without errors but it is doing neither of these. I still allows me to place any object in any order, and when I examine it won't return the included object.

// Create the platform object
const platform = createItem("platform", CONTAINER(), {
loc: "lost_journal",
examine:
"The platform has four small, rectangular holes in it. Chiselled by the bottom-left corner of each one are the numbers I, II, III, IV.",
});

// Define the expected order of item types
const expectedOrder = ["paper1", "paper2", "paper3"];

// Custom function to handle adding items to the platform
platform.onAddItem = function (item) {
// Get the index of the expected type for the next item
const expectedIndex = this.contents.length;

// Check if the item matches the expected type and order
if (item.type === expectedOrder[expectedIndex]) {
// Item is in the correct order, allow adding
this.contents.push(item);
// Update the examine description dynamically
this.examine = The platform has four small, rectangular holes in it. Chiselled by the bottom-left corner of each one are the numbers I, II, III, IV. and ${item.type} on it.;
return true;
} else {
// Item is not in the correct order or not one of the allowed types, prevent adding
msg("You can't do that.");
return false;
}
};


Log in to post a reply.

Support

Forums