PDA

View Full Version : Error with sf_to_wiz



DaCapn
04-04-2013, 03:02 PM
The error doesn't matter to me but thought I might raise it.

I made this script to count arrows:

silence_me
arrow_total = 0
bundle_total = 0
arrow_counts = []

action = proc { |server_string|
if server_string =~ /find (\d*) in the bundle/i
arrow_counts.push($1)
arrow_total += $1.to_i
# nil
elsif server_string =~ /surrounded by a scintillating|arrow has been crafted|nothing unusual|aura of holy light/i
arrow_counts.push("1")
arrow_total += 1
elsif server_string =~ /individual projectile|^.$/mi
else server_string
end
}
DownstreamHook.add('arrowcount', action)
GameObj[Lich.quiver].contents.find_all { |obj| obj.name =~ /arrow|bolt/ }.each { |bundle|
bundle_total += 1
fput "look ##{bundle.id}"
}
DownstreamHook.remove('arrowcount')

respond("\n\t### Arrows: #{arrow_total}, Bundles: #{bundle_total}")
respond("\t### Bundle Counts: #{arrow_counts.join(", ")}\n\n")

With "nil" commented out, I get the following (I just used nil to hide the error, the script still counts my arrows just fine with or without it):

--- Lich: arrowcount active.
--- Error: sf_to_wiz: private method `scan' called for 29:Fixnum
$_SERVERSTRING_: You carefully count the <a exist="67632545" noun="arrows">arrows</a> and find 29 in the bundle, each one being a whalebone arrow, with a strength of 20 and a durability of 40. The <a exist="67632545" noun="arrows">arrows</a> are surrounded by a scintillating white light.
H>--- Error: sf_to_wiz: private method `scan' called for 59:Fixnum
$_SERVERSTRING_: You carefully count the <a exist="67632642" noun="arrows">arrows</a> and find 30 in the bundle, each one being a whalebone arrow, with a strength of 20 and a durability of 40. The <a exist="67632642" noun="arrows">arrows</a> are surrounded by a scintillating white light.
H>--- Error: sf_to_wiz: private method `scan' called for 89:Fixnum
$_SERVERSTRING_: You carefully count the <a exist="67632563" noun="arrows">arrows</a> and find 30 in the bundle, each one being a whalebone arrow, with a strength of 20 and a durability of 40. The <a exist="67632563" noun="arrows">arrows</a> are surrounded by a scintillating white light.
H>--- Error: sf_to_wiz: private method `scan' called for 119:Fixnum
$_SERVERSTRING_: You carefully count the <a exist="67632571" noun="arrows">arrows</a> and find 30 in the bundle, each one being a whalebone arrow, with a strength of 20 and a durability of 40. The <a exist="67632571" noun="arrows">arrows</a> are surrounded by a scintillating white light.
H>--- Error: sf_to_wiz: private method `scan' called for 143:Fixnum
$_SERVERSTRING_: You carefully count the <a exist="64351241" noun="arrows">arrows</a> and find 24 in the bundle, each one being a whalebone arrow, with a strength of 20 and a durability of 40. The <a exist="64351241" noun="arrows">arrows</a> are surrounded by a scintillating white light.
H>
### Arrows: 143, Bundles: 5
### Bundle Counts: 29, 30, 30, 30, 24

--- Lich: arrowcount has exited.

Tillmen
04-04-2013, 03:59 PM
That's not so much a bug as it is a misuse of DownstreamHook. When you comment out the nil, the last line executed in the action proc is "arrow_total += $1.to_i" when server_string =~ /find (\d*) in the bundle/i. The value of the last line executed is the value of arrow_total, which is an integer. This is what the proc returns, and this is what's passed to any other DownstreamHooks and then to sf_to_wiz as the server string. If you want to hide the server string from the game window, having a nil there is correct. If you want the real server string or a modified one to show up in the game window, then that's what the action proc should return. If you don't want to hide or modify any server strings, then DownstreamHook is the wrong thing to use.

DaCapn
04-04-2013, 07:52 PM
I see. I think I confused myself at some point because I'm used to making return explicit. I was thinking it was always nil unless explicitly stated. Thanks. Makes perfect sense.

Tillmen
04-04-2013, 08:03 PM
I should probably point out now that explicitly returning from a proc gives a warning in Ruby 1.8 and an error in Ruby 1.9. I was using the term return kind of loosely.