Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Using if and goto together (in Harlowe)?

edited September 2015 in Help! with 2.0
Hi,

I'm very new to Twine. I have some bugs in my first story, and I think they MIGHT be because I'm using goto incorrectly. I assumed that when goto takes you to another passage, it forgets about any instructions that come after the goto. So you wouldn't need to use (else:) because it would never read that line anyway. But now I'm wondering if that's wrong? Might it eventually come back and execute code after the goto?

Just for reference, here's a simplified version of what I'm trying to do. It loops back to the "Test Whose Turn" passage multiple times:

TEST WHOSE TURN
(if:$badguyhp<1)[(goto:"You Win")]
(if:$hitpoints<1)[(goto:"Aargh You Lose")]
(if:((random:1,10)+$whoseturn)<5)[(goto:"Enemy Turn")]
Attack Bad Guy!
Run Away!

ENEMY TURN
(if:$whoseturn<0)[(set:whoseturn to 0)]
(set:$whoseturn to $whoseturn+1)
(set:$hitpoints to $hitpoints-(random:1,5))
(goto:"Test Whose Turn")

ATTACK BAD GUY
(if:$whoseturn>0)[(set:whoseturn to 0)]
(set:$whoseturn to $whoseturn-1)
(set:$badguyhp to $badguyhp-(random:1,5))
(goto:"Test Whose Turn")

... i.e. with every loop where the bad guy gets two turns, or three turns, etc., it becomes more likely that the player gets to go next (and vice-versa).

There's a lot of other code involved so the problems might be something else entirely, but this is my best guess so far! Thank you in advance!

Comments

  • I ran the following simple test, it consists of two passages. (Start and Result)
    a. Start
    (set: $var to "A")
    (goto: "Result")
    (set: $var to "B")
    
    b. Result
    Var equals: $var
    
    ... and as expected the output was: Var equals: A

    So based on the above it would appear that the (goto:) macro interrupts the processing of the current passage and instantly moves the Reader to the target passage.
  • OK thanks! I'll keep thinking / testing. I'm sort of wondering if the problem might crop up if the Result passage returns you to the Start passage ... I should be able to modify your example to test for that.
  • I modified the Result passage to have a link to the Start passage, I clicked the link and ended back on the Result passage with the same output as before:
    Var equals: $var
    
    [[Go To Start->Start]]
    
    Let us know if you need help testing/debugging your code, although you will then need to make the story available somehow with instructions on how to get to the passage that needs debugging.
Sign In or Register to comment.