Adventure Game Studio

AGS Support => Modules, Plugins & Tools => Topic started by: timid_dolphin on Sun 20/02/2022 04:44:01

Title: Replace Inventory Item with other Inventory Item Helper Function
Post by: timid_dolphin on Sun 20/02/2022 04:44:01
I've got a few helper functions which I think would be pretty much universally useful for making adventure games.

For example, this basic but super useful function:

Code (ags) Select

function replaceInvItem(InventoryItem* turnThis, InventoryItem* intoThis)
{
  int index;
  for (int i = 0; i < invCustom.ItemCount; i++) {
    if (invCustom.ItemAtIndex[i] == turnThis) index = i;
  }
  player.LoseInventory(turnThis);
  player.AddInventory(intoThis, index);
}


All it does is replace one inventory item with another at the same index, so if you're mixing drinks in the inventory, you'd just call:

Code (ags) Select

replaceInvItem(iTomatoJuice, iBloodyMary);
player.loseInventory(iVodka);


Also note that invCustom needs to be changed to whatever the name of your inventory window is.

EDIT: My sincere apologies, I'm going to get myself into trouble by not reading the forum rules. I now realise this doesn't fit the guidelines for a module on this board.
I have a few of these handy functions which I think would be really helpful, especially for beginners, I was thinking of putting them together in a sort of handy-helper library.

They include handy functions that:
-capitalise the first letter of a string
-highlight the inventory cursor over a hotspot
-Character.InRect()  -check if a character is within a rectangle

If there's interest in this sort of thing, maybe we can put together an open source collection of handy helper functions?
Title: Re: Replace Inventory Item with other Inventory Item Helper Function
Post by: selmiak on Tue 10/05/2022 11:07:13
this is absolutely helpful but not a module at all!