Howdy, Stranger!

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

Links reset my variables!

edited April 2015 in Help! with 2.0
Hi Everyone,

  I am really new to Twine and I have been following some tutorials to start my story.  I am using Harlowe story format.

  The problem I am having at the moment is that the value of the variables I set with the links, get reset some how when I go back to the previous passage, even though the previous passage does not have any macro resetting the variable values.  

  Is there a way for Twine to remember when I change a variable until I change it again?

  Does it work with the following syntax?

 (link: "whatever")[(set: $variable to false) (goto:"previousPassage")]

If not, what how can I express it so that when someone clicks on a link, it changes the value of the variable, and then it REMEMBERS the change when the person leaves that passage or goes back to a previous one?

Any help you can offer would be greatly appreciated.  I haven't been able to solve this myself, nor find any answers on the forum (which is not easy to use, btw).  

Thanks.

Comments

  • When you say "go back to the previous passage", do you mean by clicking a link in your story, or by using the undo button on the left?
  • Sorry for not clarifying.  I mean when I click a link going back to the previous page.  Even if I do use the undo button, the same effect happens (ie. the new variable value set at the link macro is not remembered).

    And this effect happens if I use a dynamic link going back to the previous page, or if I use a direct [[back to page|page]] link to the previous passage.

    Is this common behaviour of the (link:) macro, and should I be using some other macro to make the change in the variable stay.
  • edited April 2015
    Doesn't sound like intended behaviour, no. But as a workaround, try setting the variable not on the link itself, but at the very start of the passage you are linking to. End result is the same, but it should stick.
  • Hmm, perhaps we are getting somewhere.  Okay, I will give that a try.  Though I was wondering if there is a way of changing the variable and having it stick just by clicking a link.

    Does anyone know?  
  • (link: "whatever")[(set: $variable to false) (goto: "previousPassage")]


    That should work, as far as I know...

    Clicking the undo button will always undo any changes to variables, but clicking a link to go to, for example, the previous passage according to the history macro should work. If you're using a link to replicate the undo button somehow, though, it would also undo setting the variable.

    Is the link format you gave actually what you're doing that isn't actually setting the variable, or is there an additional step?
  • Hi InspectorCaracal,

      Thanks for your input.  You are right that there are additional steps I didn't mention which, thanks to you, have helped me pin point the problem (though not solve it yet).  Sorry about this.  I am really new to all this stuff.

      The problem seems to be when I assign the datamap to another variable, and then try to set a new key within that.  When I use the original datamap variable it works, but when I assign the datamap name to another variable to then access the values and keys through that, it doesn't work.  (sorry if I am not explaining this, I have only learned all about this stuff a day ago!)

    For example, I have something similar to this.

    In 1st Passage:

    (set: $dmName01 to (datamap: "name", "john", "alive", false, "points", 0))
    (set: $dmName02 to (datamap: "name", "peter", "alive", false, "points", 0))
    (set: $dmName02 to (datamap: "name", "jason", "alive", false, "points", 0))
    (set: $gameCharacter to "")

    Welcome to game.

    [[Go to 2nd Passage|2nd Passage]]

    ------------------------

    THEN IN 2nd Passage

    If you want to use John (link: "click here")[(set:$gameCharacter to $dmName01)(goto: "3rd Passage")
    If you want to use Peter (link: "click here")[(set:$gameCharacter to $dmName02)(goto: "3rd Passage")
    If you want to use Jason (link: "click here")[(set:$gameCharacter to $dmName03)(goto: "3rd Passage")

    -----------------

    THEN IN 3rd Passage there is something like this:

    To become alive (link: "click here")[(set: $gameCharacter's alive to true)(goto: "4th Passage")]

    To earn 10 points (link:"click here")[(set: $gameCharacter's points to 10)(goto: "4th Passage")]

    ---------------------------------------

    THEN IN 4th Passage

    Hi (print:$gameCharacter's name), you have (print:$gameCharacter's points) points!

    -------------------------------

    Now, in the example above, it will not work for me.  It prints out the following:

    Hi I can't find a 'name' data key in the number 0, you have I can't find a 'points' data key in the number 0 points!

    ---------------------

    Obviously, I am doing something wrong.  I am a total newby at this, so I have no idea what it is that I am doing wrong and how I can use variables for the datamaps so that it will work in a way that no matter what character someone chooses, it will display their results.

    I hope this example helps to clarify the problem I have created.  

    Thanks for any help you can give.


  • edited April 2015
    [quote]
    Hi (print:$gameCharacter's name), you have (print:$gameCharacter's points) points!
    [/quote]

    Is this drawn from an example you copied?

    Bear in mind that if you can't get datamaps to work it is easy enough to do what you want with a string of nested "if" statements and different variables. 

    EDIT: Also these new forums don't seem to have any quoting, which is going to get difficult...
  • [quote]
    THEN IN 2nd Passage

    If you want to use John (link: "click here")[(set:$gameCharacter to $dmName01)(goto: "3rd Passage")
    If you want to use Peter (link: "click here")[(set:$gameCharacter to $dmName02)(goto: "3rd Passage")
    If you want to use Jason (link: "click here")[(set:$gameCharacter to $dmName03)(goto: "3rd Passage")
    [/quote]

    The last three lines of your 2nd Passage are missing end square brackets ]

    [code]
    If you want to use John (link: "click here")[(set:$gameCharacter to $dmName01)(goto: "3rd Passage")]
    If you want to use Peter (link: "click here")[(set:$gameCharacter to $dmName02)(goto: "3rd Passage")]
    If you want to use Jason (link: "click here")[(set:$gameCharacter to $dmName03)(goto: "3rd Passage")]
    [/code]
  • Hi greyelf,

      Sorry to be taking up time with silly mistakes that distract from the actual problem I am having in Twine. 

     In the code on my twine file the brackets are there and it still doesnt work.  In fact, it behaves unpredictably.

      Just curious, if you set up the story as I have above (but with the brackets closed) does it work for you?  I'll attach a copy of the html file for the example above, which generates an error when I click on the link to earn points, to see if you reproduce the same error.  

      Thanks for all your help with this.




  • Hi Claretta,

      you mentioned that IF I can't get datamaps to work..., etc.  is that because there is a problem with using datamaps?  (ie. sometimes they don't work?)  Is there a way to use them to ensure that they DO work, and is there a way of asigning datamap names to other variables as in my example, so that I don't have to use a whole bunch of if statements?

    Otherwise, what would the alternate if statements look like using the examples above?


  • edited April 2015
    I know nothing about datamaps so can't tell you how reliable they are. But I could accomplish the same thing with if statements quite easily by dividing them up. E.g for John (bearing in mind I am not applying code syntax:

    Have variables of $choice, $johnpoints and $johnstatus.

    If player chooses John, set $choice to John, $johnpoints to 10, and $johnstatus to alive. 

    Then you might write something like: If $choice is John, (print $Johnpoints)  (print $johnstatus), elseif $choice is Peter, (print $Peterpoints) (print $peterstatus).


    I don't know how conductive Harlowe is to this sort of thing, so datamaps may be more attractive there. In Sugarcube I can just write a maze of if statements and put them in a widget I can call later on so I don't need to write the maze again. Hence why using heaps of if statements doesn't phase me.  


  • In 1st Passage you assign both the peter and jason datamaps to the same variable $dmName02. Change the assignment of the jason datamap to be $dmName03 and the code appears works.

  • hi greyelf,

    thank you. I was obviously making mistakes in the code. sorry about that. If I made so many mistakes in the brief example, i probably made a lot more in the main one i was using, and that's why it wasn't working.

    I have now redone a lot of my work and worked out another method for achieving what I wanted, though it would be too complicated for me to try to explain it here, though it was more along the lines of what Claretta suggested, and using more if statements with other variables. It all works now and the change in variables stick.

    I appreciate all the help you all gave. Thank you very much, and sorry for the extra work I caused by not checking thoroughly my example case.

  • Sorry to barge in - this isn't something to do with <<back>> vs <<return>> is it? I use a couple different choice systems and usually "back" resets variables while "return" does not. Is that what OP meant by "going back"?

    Ignore if I've gotten Twine and another system mixed up.
  • Ignore if I've gotten Twine and another system mixed up.
    No, you are correct, the Twine story formats do work that way.

    Or at least they are meant to but I did notice that datamaps in Harlowe don't work this way.

    eg. Create the following three passages: (Init, Start, Next Passage)
    note: I am use TWEE notation.
    :: Init
    (set: $datamap to (datamap: "name", "fred", "age", 10))
    (goto: "Start")
    
    
    :: Start
    Your name is (print: $datamap's name) and you are (print: $datamap's age) years old.
    [[Next Passage]]
    
    
    :: Next Passage
    (set: $datamap's name to "tom")(set: $datamap's age to 20)
    
    Your name has been changed to (print: $datamap's name) and you are now (print: $datamap's age) years old but this <b>should</b> change when you go back to the previous passage but <b>does not!</b>
    
    If you go to the next passage and then use the built-in undo button to go back the changes should undo but don't.
Sign In or Register to comment.