This would be easier to debug if we could see the file you're reading from, but from the output that your script uses, I'm guessing it's formated like:
Code:
sapphire
diamond
emerald
gem
Your problem is that you're including the newline at the end of each line when you compare your strings. That's why your output looks like:
Code:
[loottest: Comparing palimpsest
and gem]
[loottest: Comparing paper
and gem]
[loottest: Comparing scroll and gem]
Guessing the last line of your file does NOT include a newline from the output of the compare with scroll.
Anyway, the problem is that your array is populated with incorrect values and looks something like this: [ "diamond\n", "sapphire\n", "emerald\n" ]. Since the string you're reading from the game does not include the newline, the script doesn't recognize them as matching because they aren't the same and don't actually match.
This is a very common mistake, so don't feel bad about making it. Since this is a common operation in most programming languages, Ruby has a built in function that does the work for you, chomp(). So the solution is to change:
Code:
#testloot
f = File.new("c:/Lich/scripts/loot.dat", "r")
$array = f.readlines
f.close
to
Code:
#testloot
f = File.new("c:/Lich/scripts/loot.dat", "r")
$array = f.readlines.map { |line| line.chomp }
f.close
which should fix your problem. This just tells the script to chomp each line of input before returning it back to be added to the array.
Also, you're reinventing the wheel a bit in the way you're doing things. Testing whether a string of arrays contains a specified string is also a very common programming idiom and Ruby again makes it easy for us to do so. Instead of testing each value yourself using array.each, you can use the include? function that Ruby provides.
Code:
if array.include?( maybe_loot )
... something
else
... something else
end
Hopefully this will help you improve your script.