There should be a better way you can write that check with the any? method from Enumerable.
target = opponents_unit.smooth_target(@target_index) # to select the target
backstab_check = false
for key in target.state_turns.keys
backstab_check = [6,8,10,11,12,13,14,15,16,21,30].any? {|v| v == key}
end
if backstab_check
targets.push(target)
end
any? is a method from the module Enumerable. any? will evaluate if target.state_turns.keys matches any of the specified values(hence "v" being used) and will return TRUE if any of them match. If none of them match, it'll return FALSE.
It's my first time using a built in module so if what I wrote above doesn't work, you can reference this example.
Returns FALSE when all items are false. If any item is true, immediately returns TRUE.
When using a block, evaluates the block against each item and returns FALSE if all outcomes are false.
If the block returns TRUE at any time, immediately returns TRUE.
Shinami: FYI, "block" refers to the [1,2,3] being checked since it's a "block" of data. I think. >.>
p [1,2,3].any? {|v| v > 3} # => false
p [1,2,3].any? {|v| v > 1} # => true