Howdy, Stranger!

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

Universal/Continual Checks/Statements

Hello

I'm using twine 1.4 and sugarcane.

I want to create a passage where I can write if statements that will always be checked (at least I think that's what I want).

If I have a 24 hr clock, I want it to reset to 0 when it gets to 24. So I think I want something like:
<<if $time is gte 24 set $time = $time - 24 and $day = $day +1>>

So that any excess over 24 is added to the new day. Firstly, is that right?

Secondly, how do I make this a continual check so I don't have to put it in every single passage? Is that what 'script passages' are for?

While I think of it and I hope this is OK to put in the same question; what do I need to do if I want to override such a check?

Comments

  • I'm new to Twine. Started on it 2 days ago. I have only seen Harlowe syntax but I can see what you are trying to achieve.

    If you are resetting to 0 each day I would use

    set $time = 0 rather than set $time = $time -24

    As for making the statement check for every passage, one way to do this is to put the code in a seperate passage and mark it with a tag called 'header' or 'footer'. Passages marked header will be displayed on every 'turn' before other passages, so your code would be executed, then the passage displayed. Passages marked with 'footer' will be displayed on every 'turn' after any other passages so in that case the passage would be displayed and then your code would be excecuted.

    I've used this technique in my own game to keep a track of the player's current 'location' in the story which I find useful if I want to check if certain other characters or objects are in the same 'location' or if I want to redirect them to a 'status' passage that should return the player to where they were before after reading.
  • ffs wrote: »
    If I have a 24 hr clock, I want it to reset to 0 when it gets to 24. So I think I want something like:
    <<if $time is gte 24 set $time = $time - 24 and $day = $day +1>>
    
    So that any excess over 24 is added to the new day. Firstly, is that right?
    Not quite—see below for a correct example.

    ffs wrote: »
    Secondly, how do I make this a continual check so I don't have to put it in every single passage? Is that what 'script passages' are for?
    Not as such, script-tagged passages are for executing JavaScript during story startup. That said, such a passage may be used to set up what you want—my suggestion does so, in fact.

    ffs wrote: »
    […] what do I need to do if I want to override such a check?
    The easiest thing would probably be to set a variable prior to navigating to a new passage.


    Assuming you want the new day check to happen each turn—i.e. every time passage navigation occurs—you could do something like the following in Sugarcane—not to be confused with SugarCube, which already has similar functionality built-in.


    The following sets up a special passage named PassageReady which is silently—i.e. no output is generated—run just before the incoming regular passage each turn: (goes in a script-tagged passage)
    prerender['special-passage-ready'] = function () {
    	if (tale.has('PassageReady')) {
    		new Wikifier(document.createDocumentFragment(), tale.get('PassageReady').processText());
    	}
    };
    


    Now that the processing for it has been set up, you should create a passage named PassageReady and place something like the following in it:
    <<set $time to $time + 1>>
    <<if $time gte 24>>
    	<<set $time to 0>>
    	<<set $day to $day + 1>>
    <<endif>>
    
    Each turn that will automatically increment $time and check to see if a new day has arrived. Since you said that you did not want to have to do the new day check manually, I've assumed that you also want time to tick forward automatically. If not, simply remove the first line.


    You should also create a passage named StoryInit, if you don't already have one, and place something like the following in it:
    <<set $time to 0>>
    
    That will initialize $time so that it has a value when the story starts. You should actually initialize it to whatever you want the starting hour to be.

    That should more or less do what you want.

    As for making the statement check for every passage, one way to do this is to put the code in a seperate passage and mark it with a tag called 'header' or 'footer'. […]
    While similar features exist in other story formats—e.g. SugarCube—the special header and footer tags are unique to Harlowe.
  • Oh, thanks guys! I'll get on that when I can and give it a test.

    Cheers!
Sign In or Register to comment.