Too many branches + Multiple Subtracts based on bool

Hi two questions:

Firstly is there a neater way to for something that has to do multiple boolean checks e.g multiple branches. Currently I check an array too what item is in a inventory slot. If the name of the item is true it will fire. If false It will move onto the next branch in a long list. Some checks has 20 items to go through and thus 20 branches which takes up lots of space. How can I Make this cleaner?

Then secondly depending on which boolean triggers each item costs a different amount of money. How can I set the money to a different subtract per each bool instead of having to make a seperate Substract and Set everytime.

When its just a few items this is okay. But I want to scale up to thousands of items and values which will take way to long to do each item like this and not enough space on the graph to track it all

1 Like

You can use a Make Map node and subtract integers based on the string keys :cowboy_hat_face:

Something like this is not done with string comparison (probably the worst method :innocent:) or branches. If you have a 1000 items, you would not be relying on enumeration either.

One of the more classic ways is to create a Name|Struct map association.

  • a struct that holds onto the info about the item:

  • a map that associates a Name with the abovementioned struct:

You can utilise the same approach when creating an item database (data table)

  • to fetch something, one would:

This way you never need to iterate over any elements, you state what you want, and you get it.


Consider having a look at the links. It also may not be a bad idea to grab an inventory tutorial and scrub through it, even if it’s just to get a general workflow.

use swithc on string node

Please don’t. @MIkasa1009 Would you really like to mistype 50 of your 1000 items? And have a node with 1000 entries?