Is my logic clear on how to get this done?(stopping a foreach script)
Talon
26 Oct 2016, 13:13Conceptually 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 Pixie
26 Oct 2016, 14:19The 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.
Talon
26 Oct 2016, 14:35I think i'll try the later, its something that makes so much sense, just never occurred to me to try it that way