How to efficiently check equipped items?

Godot Version: 4.7

Question:

So I’m working on a game which will have items (“Artefacts”) that all have some effect on the game e.g. more money at the end of round, damage multiplier etc. , I wanted to collect all their functions in one global script so that items that proc at the end of round or when a bullet hits can be called all at once. It’s been working great for me so far, however:

This is acceptable for now, however I’m afraid it will be troublesome when the game has like a hundred implemented items that activate on every bullet impact when only two are actually active in the inventory. I feel like checking 100 “if” statements would slow down the game especially when only 1-2 are relevant.

Any ideas how to improve this?

You could use signals for this:
Every condition that could trigger an effect emits a signal. Every artefact has a function for applying it’s effect and defines which signal triggers it.
When any artefact is equipped, you connect the specified signal to that artefact’s function. When unequipped, you disconnect it.

Then your main loop would only have to emit the signals, without needing to care what functions are currently connected / which artefacts are equipped.

Oh my God that’s mad valid, thank you so much!