I'm not sure which command is changing the gem. Just to make sure it wasn't "gemarray" (was pretty sure it wasn't), I changed that to just array. Wasn't it.
Here's a snippet of what it's doing, along with the full code.
--- Lich: jarwip active.
[jarwip]>get jar from my backpack
You remove an opalescent glass jar containing green aventurine stones from in your heavy backpack.
>
[jarwip: green aventurine stone]
[jarwip]>look in my sack
>
In the ivy-stitched sack you see a large gold nugget, a piece of brown jade (2), some green ora-bloom, a piece of polished ivory, a gold nugget, a piece of white jade, a platinum nugget and the following:
41 Gem: a piece of blue ridge coral, a white opal (3), an aquamarine gem (3), a smoky topaz, a pink rhodochrosite stone (2), a snowflake zircon, a golden beryl gem (2), some polished red coral (4), a bright chrysoberyl gem (2), a red spinel, a pink topaz (2), a clear tourmaline, a green aventurine stone, a golden topaz, a pink tourmaline, some polished pink coral, a black tourmaline, a piece of golden amber (2), a turquoise stone, a green malachite stone (3), a piece of cat's-paw coral, a piece of flower coral, a violet spinel, a blue lace agate, a blue-white frost opal, a blood red garnet and a green tourmaline.
(49 Total)
>
[jarwip: aventurine stone]
[jarwip: white opal]
[jarwip]>get white opal from my sack
You remove a white opal from in your ivy-stitched sack.
>
[jarwip]>put white opal in my jar
The glass jar already contains green aventurine stones, so you think better of mixing in your white opal.
>
[jarwip: aquamarine gem]
Code:
#!/usr/bin/env ruby
array = [ "black opal", "blue spinel", "pink sapphire", "rhodochrosite stone", "mother-of-pearl", "white opal", "almadine garnet", "mottled agate", "black jasper", "yellow jasper", "pink topaz", "cordierite", "yellow sapphire", "star sapphire", "pink spinel", "aquamarine gem", "sardonyx stone", "labradorite stone", "bloodstone", "aventurine stone"]
result = dothis "get jar from my #{Lich.jarsack}", /^You remove/
if gem = /jar containing (.*?)s from/.match(result).captures.first
echo "#{gem}"
if gem =~/mother-of-pearl/
gem = "mother-of-pearl"
end
if gem =~/golden amber/
gem = "amber"
end
if gem =~ /labradorite stone/
gem = "labradorite stone"
end
if gem =~ /rhodochrosite stone/
gem = "rhodochrosite stone"
end
if gem =~ /sardonyx stone/
gem ="sardonyx stone"
end
if gem =~/yellow jasper/
gem = "yellow jasper"
end
if gem =~/black jasper/
gem = "black jasper"
end
if gem =~ /aventurine stone/
gem = "aventurine stone"
end
if gem =~ /bloodstone/
gem = "bloodstone"
end
sackscan = dothistimeout "look in my sack", 5, /In the .*? you see/
contents = sackscan.scan(/\b(?:#{array.join('|')})(?= and an? |,|\.)/)
echo "#{gem}"
end
if contents.include?(gem)
contents.each { |gem|
echo "#{gem}"
fput "get #{gem} from my sack"
fput "put #{gem} in my jar"
}
else fput "put jar in bin"
end
I suppose I could do a 'sort cluster #{gem} as a work around, but I'm not sure that would do it either.