Howdy, Stranger!

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

Help with if and updating variables.

So I have a problem I can't solve and reading the documentation when I'm not sure what I'm looking after have been ineffective. I have a room(guild hall) the player enters with two variables set $Introduction is 1 and $StarterGear is 0. This is a room the player is going to be entering multiple times, but the first time the player is collecting some gear.

So what I want is for the player to enter get some text have a click/button for picking up the gear and giving them some new text. Then after that they are allowed to leave through the head west passage.

Now the code below shows the "you need to pick up your gear" part and clicking on that does nothing. There was more to the code, but after fumbling around with <<replace>> and <<display>> and some <span> it wasn't working out and I decided to rebuild. 2:am is probably not the best time to learn new things :P

<<if $Introduction eq 1>>

<<if $StarterGear eq 0>>

<<click "You need to pick up your gear">><<set $StarterGear = 1>>
<</click>>


<</if>>

<<if $StarterGear eq 1>>

Head West
<</if>>
<</if>>

Comments

  • edited April 2016
    First. Please use the code tag in the future (it's the C on the edit bar).

    You probably want something like the following:
    <<if $Introduction eq 1>>\
    <<if $StarterGear eq 0>>\
    <<click [[Pick up your gear and head west|Head West]]>>
    	<<set $StarterGear to 1>>
    <</click>>
    <<else>>\
    [[Head West]]
    <</if>>\
    <</if>> 
    
    Alternatively, if you're using the latest release of Twine 2, you should be able to use a setter link with no ill effect here:
    <<if $Introduction eq 1>>\
    <<if $StarterGear eq 0>>\
    [[Pick up your gear and head west|Head West][$StarterGear to 1]]
    <<else>>\
    [[Head West]]
    <</if>>\
    <</if>> 
    

    The above examples assume that not picking up the starter gear shouldn't be an option. If it should, then you'll need something a little more complicated. For example:
    <<if $Introduction eq 1>>\
    <<if $StarterGear eq 0>>\
    <span id="starter-gear-pickup"><<click "Pick up your gear">>
    	<<set $StarterGear to 1>>
    	<<replace "#starter-gear-pickup">>You've picked up and equipped your gear.<</replace>>
    <</click>></span>
    
    <</if>>\
    [[Head West]]
    <</if>> 
    


    PS: About the tags used in this thread. For future reference, SugarCube is one word, so the tag really should be "sugarcube 2", rather than "sugar cube 2".
  • Thanks! Your help and some sleep made me see that I was trying to do something unnecessary in making picking up the gear something to click on, as it is not supposed to be a choice.
Sign In or Register to comment.