Howdy, Stranger!

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

Setting "Night Time" and "Day Time"

Hi, I'm kind of new to Twine, and I'm currently using Sugarcube 2.x.
I would really like some help. I want to try and set it so that after say 15 turns (of going into different passages), a message shows up, e.g., "the sun is going down, you need to return to camp soon".

For me two things are important:
1. It's important to be able to basically have a counter from the start of the game, for certain things to happen during specific turns, ie in turn 20 you get attacked, in turn 30 a strange man appears, etc.
2. I would like so that if it's currently between turns 20 and 25(ie, full moon), a special door appears in a certain passage/room for example.

I hope it's nothing too crazy to make this possible. Would really appreciate any help!

Comments

  • You have use a variable to track how many passages the Reader has navigated to and then use <<if>> macros in your passages to do things based on the current value of the variable.

    1. Initialize the $turns variable.
    Add the following code to your story's StoryInit special passage, if you don't have one yet then create a new passage and name it StoryInit
    <<set $turns to 0>>
    
    2. Increment the $turns variable each time the Reader navigates to a passage.
    Add the following code to your Story Javascript area, you access this area by clicking on the blue upwards pointing triangle in the lower left corner of the Passage Map.
    predisplay["Turns"] = function (taskName) {
    	State.variables.turns += 1;
    };
    
    3. Check the current value of the $turns variable in a passage
    You can add <<if>> macros to the passages in which you want something to happen when the $turns variable has the right value.
    <<if $turns is 20>>You get attacked
    <<elseif $turns is 30>>A strange man appears
    <</if>>
    
    4. Check the current value of the $turns variable in a passage Header / Footer.
    If you want to be able to check the current value in every passage displayed to the Reader then instead of adding the check to all your story passage you can use a PassageHeader or PassageFooter special passage instead.

    eg. Place the code from point 3 into a new passage named PassageHeader and navigate through your story, when you have visited 20 passages the You get attacked message should appear at the top of the page.
  • greyelf wrote: »
    2. Increment the $turns variable each time the Reader navigates to a passage.
    Add the following code to your Story Javascript area, you access this area by clicking on the blue upwards pointing triangle in the lower left corner of the Passage Map.
    predisplay["Turns"] = function (taskName) {
    	State.variables.turns += 1;
    };
    
    Alternatively, placing something like the following in the PassageReady special passage would also work:
    <<set $turns++>>
    
  • greyelf wrote: »
    2. Increment the $turns variable each time the Reader navigates to a passage.
    Add the following code to your Story Javascript area, you access this area by clicking on the blue upwards pointing triangle in the lower left corner of the Passage Map.
    predisplay["Turns"] = function (taskName) {
    	State.variables.turns += 1;
    };
    

    Thanks Greyelf. So, I tried this, and it didn't work. I know it's the second step because if I take it out it'll work I copied and pasted it into the Edit Story JavaScript, at the top (I also have the Inventory macros in there). After I paste it in, and I start the game, it'll say "Error: State is not Defined". Is there anything I'm missing...? Again, this is in Twine 2x, Sugarcube.

    Thaaanks!

  • Alternatively, placing something like the following in the PassageReady special passage would also work:
    <<set $turns++>>
    

    I tried reading through the Passageway Special Passage but I'm not sure I understand how it's used? Would it be possible if you clarified?

    Thanks for the help!
  • edited November 2015
    lorez wrote: »
    After I paste it in, and I start the game, it'll say "Error: State is not Defined". Is there anything I'm missing...?
    In your original post you stated "and I'm currently using Sugarcube 2.x." but in your most recent post to me you stated "Again, this is in Twine 2x, Sugarcube.", knowing the exact version of the story format you are using is important because there are some differences between the two story formats.

    The code in my previous point 2 assumes you are using the most recent release of SugarCube 2, if however you are using the version of SugarCube 1 that is built into Twine 2.0.8 then you need to use the following instead:
    predisplay["Turns"] = function (taskName) {
    	state.active.variables.turns += 1;
    };
    
    I tried reading through the Passageway Special Passage but I'm not sure I understand how it's used? Would it be possible if you clarified?
    To use TheMadExile's alternative special passage version of point 2 you first create a new passage and then name it PassageReady, you need to name the passage correctly as it wont work otherwise. The <<set $turns++>> code is placed within this new passage.
  • greyelf wrote: »
    lorez wrote: »

    The code in my previous point 2 assumes you are using the most recent release of SugarCube 2, if however you are using the version of SugarCube 1 that is built into Twine 2.0.8 then you need to use the following instead:
    predisplay["Turns"] = function (taskName) {
    	state.active.variables.turns += 1;
    };
    
    I tried reading through the Passageway Special Passage but I'm not sure I understand how it's used? Would it be possible if you clarified?
    To use TheMadExile's alternative special passage version of point 2 you first create a new passage and then name it PassageReady, you need to name the passage correctly as it wont work otherwise. The <<set $turns++>> code is placed within this new passage.

    Thanks again greyelf! It worked! Sorry took so long to respond.
  • Hey last question on this. I'm trying to use the sample example here but want to try it out for Harlow and it's not working. Is the code very different? It said predisplay isn't set.

    predisplay["Turns"] = function (taskName) {
    State.variables.turns += 1;
    };
  • lorez wrote: »
    ... try it out for Harlow and it's not working. Is the code very different? ...
    As far as I know Harlowe does not have a feature like predisplay, although you could try using a header tagged passage instead.

    The following consists of a passage named Turns which has a header tag:
    (set: $turns to it + 1)
    
    ... you will need to initialize the $turns variable in your startup tagged passage:
    (set: $turns to 0)
    
    ... now for the tricking part, hiding both the header and startup tagged passages so that their content never accidental appears at the top of the page. You can do this by adding the following CSS to your Story Stylesheet area, it depends on the header tagged passage have a name of Turns.
    tw-include[type="startup"], tw-include[type="header"][title="Turns"] {
    	display: none;
    }
    
  • It worked! Thank you very much!
Sign In or Register to comment.