Howdy, Stranger!

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

Help please, Twine 2.0 SugarCube

edited March 2015 in Help! with 2.0
Two issues with this code:

The drinks variable never goes above 1. Also the drinks = 0  text never triggers. I have a display in the previous section confirming drinks = 0

Please have a look at the code and see what i am doing wrong:

"<<if $drinks = 0>>
She looks at your drink and says "I don't handle alchool well..."

However, she finds it better to just to as you say and starts drinking.

She makes a very disgusted face as she lets the drink go down her throat and you wonder if she has ever drank before.

<<set $drinks = $drinks +1>>

<<else>>
This time around, she drinks it better, still making a disgusted expression but less than before.

<<set $drinks = $drinks +1>>

<</if>>

<<print $drinks>>
What do you tell her now?"

Thanks for your help.  :)

Comments

  • The post editor has markup specifically for code snippets, please use it.


    You're using an assignment operator (=) inside a conditional expression (see: &lt;&lt;if&gt;&gt; macro), which if that's what you needed and wanted to do there would be fine, except that it's not.  You should be doing something like the following:

    <<if $drinks eq 0>>
  • Thank you for the help. The eq 0 now triggers.

    However the variable never goes above 0. Shouldnt the snippet:
    <<set $drinks eq $drinks+1>>
    add 1 to the number stored in $drinks?


    Edit:

    Just tried again:
    <<set $drinks = $drinks +1>>
    works correctly :)
  • Magma wrote:

    However the variable never goes above 0. Shouldnt the snippet:
    <<set $drinks eq $drinks+1>>
    add 1 to the number stored in $drinks?


    No, because now you're using a conditional (equality) operator (eq) inside an assignment expression.  What you had previously was correct there.  You should be doing something like one of the following.

    Using the TwineScript to operator (equivalent to the JavaScript assignment operator; see: &lt;&lt;set&gt;&gt; macro):

    <<set $drinks to $drinks + 1>>
    Or the JavaScript = (assignment) operator:

    <<set $drinks = $drinks + 1>>
    Or the JavaScript += (addition assignment) operator:

    <<set $drinks += 1>>
Sign In or Register to comment.