PDA

View Full Version : Matching twice?



Morrff
08-07-2009, 04:01 AM
Is it possible through Ruby to catch two matches in the same line?

An example for instance would be. Matching the two bold parts.

Gaedrein examines the bundle of griffin talons quickly and says, "I'd say it's worth about oh... I'll pay you 5349 silvers for it."

This isn't what I'm attempting to match, but the example will do. I want the script to trigger on the first match and then grab the #'s and calculate them.

example

If (?) < 5349 then goto whatever
else
If (?) > 5349 then goto otherwhatever


If someone can show me how to do this action in Ruby that would help what I'm doing a ton. I'll also post the script for everyone to use once I'm done.

Deathravin
08-07-2009, 05:06 AM
yup yup...


result = matchtimeout 5, "quickly and says, "I'd say it's worth about oh... I'll pay you"

if result =~ /^([A-Z,a-z]+) examines the ([A-Z,a-z, ,-,\']+) quickly and says, \"I'd say it's worth about oh\.\.\. I'll pay you ([0-9]+) silvers for it\.\"$/
appraiseItem = $2
appraiseAmt = $3.to_i
#($1 would be the appraiser's name, but prolly don't want that)
else ; echo "what? I didn't get that!" ; end
It's called regex, learn it live it love it.


You don't really NEED to do that though... You already know what you're appraising. GameObj.right_hand is the object for that.

so it'd be more like:

result = matchtimeout 5, "quickly and says, "I'd say it's worth about oh... I'll pay you"

if result =~ /^.+ examines the .+ quickly and says, \"I'd say it's worth about oh\.\.\. I'll pay you ([0-9]+) silvers for it\.\"$/
appraiseItem = GameObj.right_hand
appraiseAmt = $3.to_i
else ; echo "what? I didn't get that!" ; end

Now you can do things like...



if appraiseAmt > 5349 then fput "_drag ##{appraiseItem.id} ##{savecontainer.id}"
else ; fput "sell ##{appraiseItem.id}" ; end

Joseph
08-07-2009, 03:06 PM
I do something very similar in a script that I already have written.. you can use the bolded parts of the following code as an example.


GameObj.inv.find {|obj| obj.noun == 'pouch'}.contents.each {|jar|
look_rest = Regexp.new(["you see ([^\D]+) portion(|s) of ([^\.]+)"
].join('|'), "i")
fput 'look in #' + jar.id
look_result = matchwait(/#{look_rest}/)
if look_result =~ /you see ([^\D]+) portion(|s) of ([^\.]+)/
num = $1
type = $3
end
if num.to_i > 25
unless notrans.include?("#{type}")
transfers.push(type)
handems.push(jar)
end
else
end
}