Is my logic clear on how to get this done?(stopping a foreach script)

Conceptually what I'm aiming for is this, the player encounters an NPC, engages them in conversation and if they have one of a handful of unique items(all with the attribute gem) one will be taken and the person will get a reward.

My current logic is using for each and have it check any item in the inventory for being a gemstone, while this sorta works, it takes EVERY game rather than just one..((I think I might be missing something on how to have the script stop once If finds one item that passes the check, have been looking for a stop script or similar function))

Would it be better if I tried to use a list for it?


The only way to break out of a loop early is with a return, so that would probably mean having the loop in another function, and returning the gem object from that.

An alternative would be to have a Boolean/flag that you set to true when the gem is found, and once it is true, stop doing anything in each iteration.


I think i'll try the later, its something that makes so much sense, just never occurred to me to try it that way


This topic is now closed. Topics are closed after 60 days of inactivity.

Support

Forums