In a game I'm working on some pages of a book have been lost and are spread around in the world. Now, I thought that I could use a single inventory item and add a "PageNum" property to it and then create different instances of this item in different locations, but that doesn't work. When I change the PageNum property of one, they all change.
Is there a way I can do this or do I have to have to have different inventory items for each page?
AGS does not currently allow to create new instances of built-in objects like inv items.
You can call player.AddInventory(iPage); multiple times but all this really does is increase the count stored in player.InventoryQuantity[iPage.ID].
You can also set the game to display each page individually in your inventory window but there's no way to distinguish which page the player has clicked on; to AGS it's all iPage.
I'd go with either of these two solutions:
1. create an inv item for each page (click handlers do not also need to be duplicated; you can use a single function for all items and react differently based on the page's ID)
2. use a container inventory item like a binder or folder, then use a custom struct to keep track of which pages have been found. Looking at the binder will display a dynamic message telling the player about the page numbers
Quote from: Khris on Wed 18/12/2024 11:00:492. use a container inventory item like a binder or folder, then use a custom struct to keep track of which pages have been found. Looking at the binder will display a dynamic message telling the player about the page numbers
You may also encode this information in the item's custom property too, for example, a String property that holds a comma-separated numbers of pages.
Thank you both for your suggestions. It's too bad I couldn't use code like this:
function AddPage(int pageNum)
{
InventoryItem* page = new InventoryItem;
page.SetProperty("PageNum", pageNum);
page.Graphics = ...;
page.Name = String.Format("iPage%d", pageNum);
player.AddInventory(page);
}
But I guess I have to add a bunch of the same iPageX (where X is a number) inventory items. I've already figured out how to do the rest, which includes using InventoryItem.GetByName() to get the correct page depending on the page number. I also have the rest figured out, I just didn't want to create all the inventory items in the editor, to begin with, but I guess I have to do that.