Author Topic: Iterating inventory slots  (Read 1513 times)

Offline Alpha Centauri Bear

  • Colonel
  • ****
  • Posts: 466
    • View Profile
Iterating inventory slots
« on: December 26, 2023, 11:20:29 pm »
Does the game restrict inventory slots? Like is it possible to create two left hands?
What is the best way to iterate and find a specific slot type?

Offline Meridian

  • Global Moderator
  • Commander
  • *****
  • Posts: 9091
    • View Profile
Re: Iterating inventory slots
« Reply #1 on: December 27, 2023, 12:02:02 am »
I don't understand the questions.

Offline Alpha Centauri Bear

  • Colonel
  • ****
  • Posts: 466
    • View Profile
Re: Iterating inventory slots
« Reply #2 on: December 27, 2023, 12:07:11 am »
Let's say I add this ruleset.
Code: [Select]
invs:
  - id: STR_LEFT_HAND2
    type: 1

Will it be accepted by engine? If yes, will it create any problems in the engine having three hands in the inventory now? Or any other problems or concerns?

Offline Meridian

  • Global Moderator
  • Commander
  • *****
  • Posts: 9091
    • View Profile
Re: Iterating inventory slots
« Reply #3 on: December 27, 2023, 12:26:37 am »
Will it be accepted by engine?

yes

If yes, will it create any problems in the engine having three hands in the inventory now?

no

Or any other problems or concerns?

yes, three-handed humans sounds like a concern to me

Offline Alpha Centauri Bear

  • Colonel
  • ****
  • Posts: 466
    • View Profile
Re: Iterating inventory slots
« Reply #4 on: December 27, 2023, 01:46:09 am »
yes, three-handed humans sounds like a concern to me

🤣

Thank you.

Offline psavola

  • Commander
  • *****
  • Posts: 827
    • View Profile
Re: Iterating inventory slots
« Reply #5 on: December 27, 2023, 08:13:39 am »
I do wonder, though, which hand(s) will be shown in on the battlescape, because the GUI has room only for two and a special attacks icon on top right corner. So, while creating additional inventory slots has already been done a lot of times in the mods, more "active hands" could be troublesome.

Offline Alpha Centauri Bear

  • Colonel
  • ****
  • Posts: 466
    • View Profile
Re: Iterating inventory slots
« Reply #6 on: December 27, 2023, 05:38:30 pm »
I absolutely agree and I don't plan to create another hand.
My question was how to properly iterate slots in the code. Is using hardcoded slot ID acceptable?

Code: [Select]
_game->getMod()->getInventory("STR_LEFT_HAND");

Offline Meridian

  • Global Moderator
  • Commander
  • *****
  • Posts: 9091
    • View Profile
Re: Iterating inventory slots
« Reply #7 on: December 27, 2023, 06:37:46 pm »
My question was how to properly iterate slots in the code. Is using hardcoded slot ID acceptable?

That's up to you.

You can use: _game->getMod()->getInventoryLeftHand();

Or: _game->getMod()->getInventory("STR_LEFT_HAND", true);

Or even: _game->getMod()->getInventory("STR_LEFT_HAND");
if you want to start supporting one-handed inventories in your fork, or whatever. If so, don't forget to check for nullptr.