I thought I'd try and condense things a bit for the next time round the loop
--
-- let's fast forward through that for the second loop
--
rc = narrator:play(stage) -- run it
assert_true(rc) -- not done yet
assert_equal(2, stage:num_oq()) -- two items in output queue
assert_not_nil(stage:oq(2).options) -- second item is a menu
assert_equal(2, #stage:oq(2).options) -- with two elements
stage:iq_insert(2) -- chose the second option
rc = narrator:play(stage) -- play
assert_true(rc) -- more to do
That gets as far as this:
assert_equal(2, stage:num_oq()) -- two items in output queue
At which point it bombs out with this:
1) Failure (narrator_tests.test_condition1):
test_narrator.lua:745: expected 2 but was 0
What seems to be happening is that the loop isn't breaking at the jump, but continuing down the new
narrative. I think I need jump to break the loop. The new narrative will probably open with an image, and there's no way to auto-cut based on the previous narrative.
Hmm...Jump. Lua sets the cut field as expected... mutter mutter mutter ...
OK. What's happening is that the previous section is getting further than I expected. instead of just running the two snippets, it runs the snippets, func and jump all in one. I'm not sure whether to "fix" that, or to just adapt to the way it runs. Really, I think we need an auto-cut before the func. Otherwise it's possible that the func could do something that gets wiped out but the subsequent operations.
So if I modify Narrative.lua like so, it ought to solve the problem
elseif label == "func" then
item = Func:new(raw_item)
auto_cut = true
Let's go back to the point where we just jumped narratives, and we're about to play the new narrative
--
-- check the output
--
assert_nil(narrator.userdata.sulk) -- not set yet
assert_equal(2, stage:num_oq()) -- 2 in o/p queue
assert_equal("text", stage:oq(1).type)
assert_equal("You pout", stage:oq(1).value) -- first snippet
assert_equal("text", stage:oq(2).type)
assert_equal( -- second snippet
"The door fails to open", stage:oq(2).value
)
assert_nil(narrator.userdata.sulk) -- still not set
assert_equal("sulking", narrator.narrative.name)-- same narrative
That all passes now. And we know that we're still on the "sulking" narrative, and that the sulk flag has not now been set. Now we can do the fast-forward tests with some hope of success...
--
-- let's fast forward through that for the second loop
--
rc = narrator:play(stage) -- run it
assert_true(rc) -- not done yet
assert_equal(2, stage:num_oq()) -- two items in output queue
assert_not_nil(stage:oq(2).options) -- second item is a menu
assert_equal(2, #stage:oq(2).options) -- with two elements
stage:iq_insert(2) -- chose the second option
rc = narrator:play(stage) -- play
assert_true(rc) -- more to do
This time we get an error because I haven't supplied the "moaning" narrative. Easy fix - just add this to the XML
<narrative Name="moaning">
<snippet> "Moan! Moan, moan, moan! Moan!" </snippet>
<snippet> The door remains unmoved </snippet>
<func>
userdata.moan = true
</func>
<jump target="in_the_room" />
</narrative>
And it all passes. So are we now at the top of the "moaning" narrative? After the last time, I hate to make assumptions like that...
assert_equal("moaning", narrator.narrative.name)
assert_equal(0, narrator.index)
Yes, it seems we are. Groovy. So now we need to go round the loop one more time, and this time the third option should appear.
No comments:
Post a Comment