There is a new version of the forums ready for testing. Please post here if you're willing to help test! We could also use the help of coders!

Author Topic: Replace Inventory Item with other Inventory Item Helper Function  (Read 467 times)

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: Adventure Game Studio
  1. function replaceInvItem(InventoryItem* turnThis, InventoryItem* intoThis)
  2. {
  3.   int index;
  4.   for (int i = 0; i < invCustom.ItemCount; i++) {
  5.     if (invCustom.ItemAtIndex[i] == turnThis) index = i;
  6.   }
  7.   player.LoseInventory(turnThis);
  8.   player.AddInventory(intoThis, index);
  9.  }

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: Adventure Game Studio
  1. replaceInvItem(iTomatoJuice, iBloodyMary);
  2. 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?
« Last Edit: 20 Feb 2022, 20:25 by timid_dolphin »


  • ǝsıɔɹǝxǝ ʞɔǝu puɐ uıɐɹq
    • I can help with play testing
    • I can help with proof reading
    • I can help with translating
    • I can help with web design
    • selmiak worked on one or more games that won an AGS Award!
    • selmiak worked on one or more games that was nominated for an AGS Award!
this is absolutely helpful but not a module at all!