Replace Inventory Item with other Inventory Item Helper Function

Started by timid_dolphin, Sun 20/02/2022 04:44:01

Previous topic - Next topic

timid_dolphin

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

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

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?

selmiak


SMF spam blocked by CleanTalk