PDA

View Full Version : Error with Scrolls.lic



wizgem3
10-18-2011, 05:11 PM
Anyone know why i'm getting this error?
>;scrolls sack
--- Lich: scrolls active.
[scrolls]>open sack
That is already open.
>
[scrolls]>look in sack
--- Lich: DownstreamHook: wrong number of arguments (1 for 2)
scrolls:44:in `gsub!'

In the large sack you see a sheet of faded vellum, a piece of dark paper, a sheaf of light paper, a piece of dark paper, a tattered scroll, an aged scroll, a smeared scroll, a charred scroll, a charred scroll, an aged scroll, a burnt scroll, a neatly inked scroll, an obscure scroll, a scorched scroll, a golden scroll, a glowing scroll, a tattered palimpsest, a silvery palimpsest, a wrinkled scroll, an old scroll, a crumpled scroll, a glowing scroll, a scorched scroll, a torn parchment, a pure white parchment, a glowing scroll and a large leather tome.


=begin
Read all of the scrolls in the specified container and provide a summary of all
the spells on those scrolls. WARNING: Generates a lot of screen scroll.

Current revision: 2009.12.23.01
=end
# -----------------------------------------------------------------------------
# Author: Jymamon (gs4-jymamon@hotmail.com)
#
# History:
# 2009.12.23.01 Initial version.
# -----------------------------------------------------------------------------
script.want_downstream_xml = true # Raw input wanted as we parse it for IDs

# Remove the hook on shutdown.
before_dying {
DownstreamHook.remove('AnalyzeScrollsHook')
}

# -----------------------------------------------------------------------------
# Get the name of the container from the command line
# -----------------------------------------------------------------------------
script.vars.shift
lookin = script.vars.shift

# -----------------------------------------------------------------------------
# Setup some variabples
# -----------------------------------------------------------------------------
$scrolls = Array.new
$spells = Hash.new
$container = String.new
$spell_count = 0
$scroll_count = 0

# -----------------------------------------------------------------------------
# Hook to get IDs of all items inside the named container and to capture the
# container's ID for later use.
# -----------------------------------------------------------------------------
done = false
action = proc { |line|
if line =~ /In the <a exist="(\d+)" noun=.* you see/i
$container = $1.to_s
cp_line = line
cp_line.gsub!(/In the .* you see/i)

cp_line.split(/<a/).each { |entry|
entry =~ /exist="([0-9]+)"/i
$scrolls.push($1)
$scroll_count += 1
}
done = true
DownstreamHook.remove('AnalyzeScrollsHook')
end

line
}
fput "open " + lookin

# -----------------------------------------------------------------------------
# Use the hook and wait for it to finish
# -----------------------------------------------------------------------------
DownstreamHook.add('AnalyzeScrollsHook', action)
fput "look in " + lookin
wait_until { done }

# -----------------------------------------------------------------------------
# Hook to capture the spells on each scroll.
# -----------------------------------------------------------------------------
done = false
action = proc { |line|
matchstring = "You close .* exist=\"" + $container.to_s + "\""
if line =~ /\((\d+)\) .* exist=\"(\d+)\"/i

if $spells[$1.to_s].nil?
$spells[$1.to_s] = Array.new
end

$spells[$1.to_s].push($2.to_s)
$spell_count += 1
nil
elsif line =~ /#{matchstring}/i
DownstreamHook.remove('AnalyzeScrollsHook')
done = true
line
elsif line =~ /You pull your .* closed at the neck/i
DownstreamHook.remove('AnalyzeScrollsHook')
done = true
line
else
line
end
}

# -----------------------------------------------------------------------------
# Use the hook and wait for it to finish
# -----------------------------------------------------------------------------
DownstreamHook.add('AnalyzeScrollsHook', action)
$scrolls.each { |id|
fput "read #" + id.to_s if (id.nil!)
}
fput "close #" + $container.to_s
wait_until { done }

# -----------------------------------------------------------------------------
# Now, process the results.
# -----------------------------------------------------------------------------
$spells.keys.sort{|x,y| x.to_i <=> y.to_i}.index { |spell|
respond sprintf("%4d is on %d scrolls.", spell.to_i, $spells[spell].length.to_i)
}

respond $spell_count.to_s + " total spells on " + $scroll_count.to_s + " total scrolls."

Tillmen
10-18-2011, 08:57 PM
The problem is with gsub on line 44, just like it says. You've given it a regex to match, but haven't told it what to replace it with. However, I don't think you want to do what you're trying to do. cp_line is not so much a copy of line as it is a pointer to the same string line points at. gsub! will modify the string in place, causing both to change. You probably want:

cp_line = line.gsub(/In the .* you see/i, '')

wizgem3
10-18-2011, 10:21 PM
changed to what you said and now I get this:

--- Lich: scrolls active.
--- SyntaxError: compile error
scrolls:46: syntax error, unexpected '(', expecting ')'
entry =~ /exist="([0-9]+)"/i
^
scrolls:46: syntax error, unexpected ')'
entry =~ /exist="([0-9]+)"/i
^
scrolls:56: syntax error, unexpected tIDENTIFIER, expecting kEND
fput "open " + lookin
^
scrolls:62: syntax error, unexpected tIDENTIFIER, expecting kEND
fput "look in " + lookin
^
scrolls:70: syntax error, unexpected tCONSTANT, expecting kEND
matchstring = "You close .* exist=\"" + $container.to_s + "\""
^
scrolls:70: syntax error, unexpected $undefined
matchstring = "You close .* exist=\"" + $container.to_s + "\""
^
scrolls:91: syntax error, unexpected '}', expecting kEND
scrolls:110: syntax error, unexpected $end, expecting kEND
scrolls:110:in `start_script'
--- Lich: cannot execute scrolls, aborting.
--- Lich: scrolls has exited.

Tillmen
10-18-2011, 10:29 PM
In my code that was two single quotes, not one double quote.

wizgem3
10-19-2011, 12:29 AM
Thanks Tillmen, but got another error.

>;scrolls sack
--- Lich: scrolls active.
[scrolls]>open sack
That is already open.
>
[scrolls]>look in sack
In the veniom-threaded sack you see a crumbling scroll, an obscure scroll, a torn scroll, a light scroll, a golden scroll, a luminous scroll, an ancient scroll, a shimmering scroll, a golden feather charm, a dark scroll, a smeared scroll, a faded parchment, a dark scroll, a sheet of illuminated vellum and a silvery palimpsest.
>
--- Exception: undefined method `nil!' for "135963740":String
scrolls:98:in `start_script'
--- Lich: scrolls has exited.

Tillmen
10-19-2011, 02:08 AM
Well, that's from using nil! which isn't a defined method. nil? will tell you if the variable is nil or not. You'll probably want to change the line to:

fput "read #" + id.to_s unless id.nil?

wizgem3
10-19-2011, 02:53 PM
Its almost working, but still getting errors. Thanks for the help. Paste below is what changes got me to put in.

=begin
Read all of the scrolls in the specified container and provide a summary of all
the spells on those scrolls. WARNING: Generates a lot of screen scroll.

Current revision: 2009.12.23.01
=end
# -----------------------------------------------------------------------------
# Author: Jymamon (gs4-jymamon@hotmail.com)
#
# History:
# 2009.12.23.01 Initial version.
# -----------------------------------------------------------------------------
script.want_downstream_xml = true # Raw input wanted as we parse it for IDs

# Remove the hook on shutdown.
before_dying {
DownstreamHook.remove('AnalyzeScrollsHook')
}

# -----------------------------------------------------------------------------
# Get the name of the container from the command line
# -----------------------------------------------------------------------------
script.vars.shift
lookin = script.vars.shift

# -----------------------------------------------------------------------------
# Setup some variabples
# -----------------------------------------------------------------------------
$scrolls = Array.new
$spells = Hash.new
$container = String.new
$spell_count = 0
$scroll_count = 0

# -----------------------------------------------------------------------------
# Hook to get IDs of all items inside the named container and to capture the
# container's ID for later use.
# -----------------------------------------------------------------------------
done = false
action = proc { |line|
if line =~ /In the <a exist="(\d+)" noun=.* you see/i
$container = $1.to_s
cp_line = line
cp_line=line.gsub(/In the .* you see/i,'')
cp_line.split(/<a/).each { |entry|
entry =~ /exist="([0-9]+)"/i
$scrolls.push($1)
$scroll_count += 1
}
done = true
DownstreamHook.remove('AnalyzeScrollsHook')
end

line
}
fput "open " + lookin

# -----------------------------------------------------------------------------
# Use the hook and wait for it to finish
# -----------------------------------------------------------------------------
DownstreamHook.add('AnalyzeScrollsHook', action)
fput "look in " + lookin
wait_until { done }

# -----------------------------------------------------------------------------
# Hook to capture the spells on each scroll.
# -----------------------------------------------------------------------------
done = false
action = proc { |line|
matchstring = "You close .* exist=\"" + $container.to_s + "\""
if line =~ /\((\d+)\) .* exist=\"(\d+)\"/i

if $spells[$1.to_s].nil?
$spells[$1.to_s] = Array.new
end

$spells[$1.to_s].push($2.to_s)
$spell_count += 1
nil
elsif line =~ /#{matchstring}/i
DownstreamHook.remove('AnalyzeScrollsHook')
done = true
line
elsif line =~ /You pull your .* closed at the neck/i
DownstreamHook.remove('AnalyzeScrollsHook')
done = true
line
else
line
end
}

# -----------------------------------------------------------------------------
# Use the hook and wait for it to finish
# -----------------------------------------------------------------------------
DownstreamHook.add('AnalyzeScrollsHook', action)
$scrolls.each { |id|
fput "read #" + id.to_s unless id.nil?
}
fput "close #" + $container.to_s
wait_until { done }

# -----------------------------------------------------------------------------
# Now, process the results.
# -----------------------------------------------------------------------------
$spells.keys.sort{|x,y| x.to_i <=> y.to_i}.index { |spell|
respond sprintf("%4d is on %d scrolls.", spell.to_i, $spells[spell].length.to_i)
}

respond $spell_count.to_s + " total spells on " + $scroll_count.to_s + " total scrolls."

Jymamon
10-19-2011, 11:37 PM
sI>;repos upload scrolls
--- Lich: repository active.
[repository: connecting to the server...]
[repository: updating scrolls.lic in 3 seconds... (;k repository to abort)]
[repository: done]
--- Lich: repository has exited.

sI>;scrolls harness
--- Lich: scrolls active.
[scrolls]>open harness
You open a distressed leather harness.
sI>
[scrolls]>look in harness
a white flask, a shimmering scroll, a luminous scroll, a blood-stained scroll, a tincture of torban, some wolifrew lichen, a bolmara potion, a dark scroll, an old scroll, a tattered scroll, an arcane scroll, a golden scroll, a small statue, a tincture of sovyn, a tincture of calamia, a tincture of ephlox, a tincture of brostheras, a tincture of bur-clover, a tincture of woth, some milky blue oil, some aloeas stem, an arcane parchment, a scintillating lilac potion, a tincture of aloeas, a tincture of wingstem, a tincture of talneo, a tincture of rose-marrow, a tincture of haphip, an obscure scroll, a tincture of cactacae, some ambrominas leaf, a smeared scroll and a sigil-etched orase runestaff.
sI>
[scrolls]>read #139475665
It takes you a moment to focus on the shimmering scroll.
On the shimmering scroll you see

sI>
[scrolls]>read #139475664
It takes you a moment to focus on the luminous scroll.
On the luminous scroll you see

sI>
[scrolls]>read #139475663
It takes you a moment to focus on the blood-stained scroll.
On the blood-stained scroll you see

sI>
[scrolls]>read #139475659
It takes you a moment to focus on the dark scroll.
On the dark scroll you see

sI>
[scrolls]>read #139475658
It takes you a moment to focus on the old scroll.
On the old scroll you see

sI>
[scrolls]>read #139475657
It takes you a moment to focus on the tattered scroll.
On the tattered scroll you see

sI>
[scrolls]>read #139475656
It takes you a moment to focus on the arcane scroll.
On the arcane scroll you see

sI>
[scrolls]>read #139475655
It takes you a moment to focus on the golden scroll.
On the golden scroll you see

sI>
[scrolls]>read #139475645
It takes you a moment to focus on the arcane parchment.
On the arcane parchment you see

sI>
[scrolls]>read #139475638
It takes you a moment to focus on the obscure scroll.
On the obscure scroll you see

sI>
[scrolls]>read #139475635
It takes you a moment to focus on the smeared scroll.
On the smeared scroll you see

sI>
[scrolls]>close #139475633
You close a distressed leather harness.
sI>
101 is on 2 scrolls.
103 is on 2 scrolls.
104 is on 1 scrolls.
106 is on 1 scrolls.
109 is on 1 scrolls.
110 is on 1 scrolls.
113 is on 2 scrolls.
114 is on 1 scrolls.
115 is on 2 scrolls.
117 is on 2 scrolls.
203 is on 2 scrolls.
204 is on 1 scrolls.
205 is on 1 scrolls.
208 is on 1 scrolls.
213 is on 2 scrolls.
214 is on 1 scrolls.
215 is on 3 scrolls.
303 is on 1 scrolls.
307 is on 1 scrolls.
308 is on 2 scrolls.
403 is on 1 scrolls.
411 is on 1 scrolls.
603 is on 1 scrolls.
606 is on 1 scrolls.
612 is on 1 scrolls.
613 is on 1 scrolls.
702 is on 1 scrolls.
1101 is on 1 scrolls.
1605 is on 1 scrolls.
1701 is on 2 scrolls.
41 total spells on 34 total scrolls.
--- Lich: scrolls has exited.

Tillmen
10-19-2011, 11:40 PM
Now that you're done, I should probably tell you about readscrolls.lic, which has been on the repository for quite some time...

Jymamon
10-19-2011, 11:50 PM
I'm not sure if was there when I wrote the first version or not. In any case, that (along with a handful of othes) were thrown together as part of learning Ruby for the first time. Two things I do prefer about my version, though, are that it doesn't rely on Lich.scrollsack and it sorts by spell number. Trivial enough to change in readscrolls, but then why not just have a seperate version? ;) [In fact, I maintain seperate version of ;go2 and lich that apply *.sort in all the places I think it belongs and its enough of a hassle, I never upgrade either anymore.]

wizgem3
10-20-2011, 12:13 AM
Thanks guys