Howdy, Stranger!

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

[Sugarcube] Tailored time system not functioning properly

Greetings,

Haven't been on in a while but for the most part I've been attempting to manage any problems I come across on my own, and it's been going reasonably well until this current juncture.

What I'm trying to do exactly is to convert a preset variable aka $Seconds, or something similar, into minutes. So 60 seconds would be equal to 1 minute 0 seconds, 90 seconds would be equivalent to 1 minute 30 seconds and 153 seconds would be converted to 2 minutes 33 seconds and so on, so forth. I'd prefer to do it in this manner rather than using javascript or anything else that I may have trouble integrating other systems with as essentially time will be the controlling factor in many game mechanic variables, from combat to disease incubation time to resting etc etc, so I would ideally want something that I can simply add + seconds or + minutes to any interaction and it will automatically translate onto the clock in the UI.

The following is an old draft of the code I had planned to use for this purpose.
<<nobr>><<silently>>

<<if $UITimeRestart neq true or $mm lt 0>>
<<set $mm to 0>>
<</if>>

<<if $UITimeRestart neq true or $hh lt 0>>
<<set $hh to 0>>
<</if>>

<<if $UITimeRestart neq true or $h0 lt 0>>
<<set $h0 to 0>>
<</if>>

<<if $UITimeRestart neq true or $m0 lt 0>>
<<set $m0 to 0>>
<</if>>

<<if $UITimeRestart neq true or $ss lt 0>>
<<set $s0 to 0>>
<</if>>

<<if $UITimeRestart neq true or $ss lt 0>>
<<set $ss to 0>>
<</if>>

<<if $mm gte 60>>
<<set $mm -=60>>
<<set $hh +=1>>
<</if>>
<<if $mm gte 120>>
<<set $mm -=120>>
<<set $hh +=2>>
<</if>>
<<if $mm gte 180>>
<<set $mm -=180>>
<<set $hh +=3>>
<</if>>
<<if $mm gte 240>>
<<set $mm -=240>>
<<set $hh +=4>>
<</if>>
<<if $mm gte 300>>
<<set $mm -=300>>
<<set $hh +=5>>
<</if>>
<<if $mm gte 360>>
<<set $mm -=360>>
<<set $hh +=6>>
<</if>>
<<if $mm gte 420>>
<<set $mm -=420>>
<<set $hh +=7>>
<</if>>
<<if $mm gte 480>>
<<set $mm -=480>>
<<set $hh +=8>>
<</if>>
<<if $mm gte 540>>
<<set $mm -=540>>
<<set $hh +=9>>
<</if>>
<<if $mm gte 600>>
<<set $mm -=600>>
<<set $hh +=10>>
<</if>>
<<if $mm gte 600>>
<<set $mm -=600>>
<<set $hh +=10>>
<</if>>
<<if $mm gte 600>>
<<set $mm -=600>>
<<set $hh +=10>>
<</if>>
<<if $mm gte 600>>
<<set $mm -=600>>
<<set $hh +=10>>
<</if>>
<<if $mm gte 600>>
<<set $mm -=600>>
<<set $hh +=10>>
<</if>>


<<if $hh gte 24>>
<<set $hh to 0>>
<<set $Day +=1>>
<</if>>

<<if $hh gte 10>>
<<set $h0 to "">>
<</if>>

<<if $hh lt 10>>
<<set $h0 to 0>>
<</if>>

<<if $mm gte 10>>
<<set $m0 to "">>
<</if>>

<<if $mm lt 10>>
<<set $m0 to 0>>
<</if>>

<<if $ss gte 60>>
<<set $ss -=60>>
<<set $mm +=1>>
<</if>>
<<if $ss gte 60>>
<<set $ss -=60>>
<<set $mm +=1>>
<</if>>
<<if $ss gte 60>>
<<set $ss -=60>>
<<set $mm +=1>>
<</if>>
<<if $ss gte 60>>
<<set $ss -=60>>
<<set $mm +=1>>
<</if>>
<<if $ss gte 60>>
<<set $ss -=60>>
<<set $mm +=1>>
<</if>>
<<if $ss gte 120>>
<<set $ss -=120>>
<<set $mm +=2>>
<</if>>
<<if $ss gte 180>>
<<set $ss -=180>>
<<set $mm +=3>>
<</if>>
<<if $ss gte 240>>
<<set $ss -=240>>
<<set $mm +=4>>
<</if>>
<<if $ss gte 300>>
<<set $ss -=300>>
<<set $mm +=5>>
<</if>>
<<if $ss gte 360>>
<<set $ss -=360>>
<<set $mm +=6>>
<</if>>
<<if $ss gte 420>>
<<set $ss -=420>>
<<set $mm +=7>>
<</if>>
<<if $ss gte 480>>
<<set $ss -=480>>
<<set $mm +=8>>
<</if>>
<<if $ss gte 540>>
<<set $ss -=540>>
<<set $mm +=9>>
<</if>>
<<if $ss gte 600>>
<<set $ss -=600>>
<<set $mm +=10>>
<</if>>
<<if $ss gte 600>>
<<set $ss -=600>>
<<set $mm +=10>>
<</if>>
<<if $ss gte 600>>
<<set $ss -=600>>
<<set $mm +=10>>
<</if>>
<<if $ss gte 600>>
<<set $ss -=600>>
<<set $mm +=10>>
<</if>>
<<if $ss gte 600>>
<<set $ss -=600>>
<<set $mm +=10>>
<</if>>

<<if $ss lt 10>>
<<set $s0 to 0>>
<</if>>

<<if $ss gte 10>>
<<set $s0 to "">>
<</if>>

\\\\\\\\REPEAT CODE AS NECESSARY TO ALLOW FOR NUMBERS OUTSIDE OF MAXIMUM PRESET BRACKETS\\\\\\\\\

<<if $UITimeRestart neq true or $mm lt 0>>
<<set $mm to 0>>
<</if>>

<<if $UITimeRestart neq true or $hh lt 0>>
<<set $hh to 0>>
<</if>>

<<if $UITimeRestart neq true or $h0 lt 0>>
<<set $h0 to 0>>
<</if>>

<<if $UITimeRestart neq true or $m0 lt 0>>
<<set $m0 to 0>>
<</if>>

<<if $UITimeRestart neq true or $ss lt 0>>
<<set $s0 to 0>>
<</if>>

<<if $UITimeRestart neq true or $ss lt 0>>
<<set $ss to 0>>
<</if>>
\
<<if $UITimeRestart neq true>>\
<<set $UITimeRestart to true>>\
<</if>>\

<<if $mm gte 60>>
<<set $mm -=60>>
<<set $hh +=1>>
<</if>>

<<if $mm lt 0>>
<<set $mm to 0>>
<</if>>

<<if $m0 lt 0>>
<<set $m0 to 0>>
<</if>>

<<if $hh lt 0>>
<<set $hh to 0>>
<</if>>

<<if $h0 lt 0>>
<<set $h0 to 0>>
<</if>>
<</silently>><</nobr>>

<b>$h0$hh:$m0$mm:</b>$s0$ss

<<click "Seconds Time">><<goto "Time Test">><<set $ss += random (120, 180)>><</click>>
\
<<set $UITimeRestart to true>>\

This is a draft of the time system I've been working on. I had to work around the fact that the <<repeat>> macro <b><i>still</b></i> would not function for me when:

A) I upgraded twine to the latest version
B) I tested the example provided by the sugarcube wiki with Twine 2 and using both Sugarcube 1x and Sugarcube 2x, whilst having to readapt the system to work with 2x

So I was forced to use a more long hand method, which is by no means effective AND to add insult to injury some values will not display properly, and I have no idea why. Today, I planned on restarting the whole system from the ground up because frankly this system is far too lengthy for something that sounds so ideologically simple on paper.

Today I've tried to circumnavigate the fact that the <<repeat>> macro does not seem to function properly with this instead:
<<set $minutes to 0>>
<<set $seconds to 0>>


<<set $seconds to 300>>

<<if $secondsover60 eq true>>
<<set $seconds -=60>>
<<set $minutes ++>>
<<set $secondsover60 to false>>
<<elseif $secondsover60 neq true>>
<<if $seconds gte 60>>
<<set $secondsover60 to true>>
<</if>><</if>>

<<if $seconds gte 60>>
<<set $secondsover60 to true>>
<</if>>



There are $seconds seconds and $minutes minutes.

Which also does not function properly.

Would appreciate any input/help on this matter.

Comments

  • edited April 30
    Hmmm.

    I'm not confident I understand what you're trying to do, but if you're trying to do what I think you are, why not something like:
    ::timeWidget [widget]
    <<widget "timeFormat">>\
      <<silently>>
    
        <<if $seconds gte 60>>
          <<set _op to Math.trunc($seconds / 60)>>
          <<set $minutes to $minutes + _op>>
          <<set $seconds to $seconds - (_op * 60)>>
          /% <<set $seconds to $seconds % 60>> also works, probably %/
        <</if>>
    
        <<if $minutes gte 60>>
          <<set _op to Math.trunc($minutes / 60)>>
          <<set $hour to $hour + _op>>
          <<set $minutes to $minutes - (_op * 60)>>
        <</if>>
    
        <<if $hour gte 24>>
          <<set _op to Math.trunc($hour / 24)>>
          <<set $day to $day + _op>>
          <<set $hour to $hour - (_op * 24)>>
        <</if>>
    
      <</silently>>\
    <</widget>>
    
    Usage:
    <<set $seconds += 90>>
    <<timeFormat>>
    
    If you're going to be changing the time a lot, you might want to just stick <<timeFormat>> in either your PassageDone or your PassageFooter special passage.

    Here's a testing passage:
    ::timeFormatTest
    <<timeFormat>>\
    <<print "Days: " + $day + ", Hours: " + $hour + ", Minutes: " + $minutes + ", Seconds: " + $seconds + ".">>
    
    [[Increase time by 60s|timeFormatTest][$seconds += 60]]
    [[Increase time by 240s|timeFormatTest][$seconds += 240]]
    [[Increase time by 45m|timeFormatTest][$minutes += 45]]
    [[Increase time by 300m|timeFormatTest][$minutes += 300]]
    [[Increase time by 10000s|timeFormatTest][$seconds += 10000]]
    [[Increase time by 16h|timeFormatTest][$hour += 16]]
    

    Obviously you'll want to change the variables to whatever works for you (make sure they're initialized before calling <<timeFormat>>).

    I'm not sure if this is exactly what you're asking for; I didn't quite understand all of your code or why it was coded the way it was. Let me know if I missed something.
  • Hi, if it's a time format you want to use,

    Give a look to this thread : maybe you will find what you need :
    https://twinery.org/forum/discussion/3195/clocks-still-driving-me-nuts/p1

    Have a good day.
  • Chapel wrote: »
    Hmmm.

    I'm not confident I understand what you're trying to do, but if you're trying to do what I think you are, why not something like:
    ::timeWidget [widget]
    <<widget "timeFormat">>\
      <<silently>>
    
        <<if $seconds gte 60>>
          <<set _op to Math.trunc($seconds / 60)>>
          <<set $minutes to $minutes + _op>>
          <<set $seconds to $seconds - (_op * 60)>>
          /% <<set $seconds to $seconds % 60>> also works, probably %/
        <</if>>
    
        <<if $minutes gte 60>>
          <<set _op to Math.trunc($minutes / 60)>>
          <<set $hour to $hour + _op>>
          <<set $minutes to $minutes - (_op * 60)>>
        <</if>>
    
        <<if $hour gte 24>>
          <<set _op to Math.trunc($hour / 24)>>
          <<set $day to $day + _op>>
          <<set $hour to $hour - (_op * 24)>>
        <</if>>
    
      <</silently>>\
    <</widget>>
    
    Usage:
    <<set $seconds += 90>>
    <<timeFormat>>
    
    If you're going to be changing the time a lot, you might want to just stick <<timeFormat>> in either your PassageDone or your PassageFooter special passage.

    Here's a testing passage:
    ::timeFormatTest
    <<timeFormat>>\
    <<print "Days: " + $day + ", Hours: " + $hour + ", Minutes: " + $minutes + ", Seconds: " + $seconds + ".">>
    
    [[Increase time by 60s|timeFormatTest][$seconds += 60]]
    [[Increase time by 240s|timeFormatTest][$seconds += 240]]
    [[Increase time by 45m|timeFormatTest][$minutes += 45]]
    [[Increase time by 300m|timeFormatTest][$minutes += 300]]
    [[Increase time by 10000s|timeFormatTest][$seconds += 10000]]
    [[Increase time by 16h|timeFormatTest][$hour += 16]]
    

    Obviously you'll want to change the variables to whatever works for you (make sure they're initialized before calling <<timeFormat>>).

    I'm not sure if this is exactly what you're asking for; I didn't quite understand all of your code or why it was coded the way it was. Let me know if I missed something.

    Hey, I like that a lot! Thank you! I did a bit of fiddling with it myself and I can also translate it very easy to integrate with other macros, meaning it's a very effective system for what I'm attempting to do! Thank you very much!

    I did notice whilst testing that this particular script will only work whilst using Sugarcube 2x.. Is there any possibility that a variation of this could be ported to work with sugarcube 1? I've been trying to leave the consideration of whether I want to transition or not till last seeing as how Sugarcube 2 makes some rather radical changes to the stylesheet (media screen, font, text size, layout, etcetera) along with other minute differences, so I haven't been all that keen to switch over just yet, largely in part due to the fact that I have so many other concerns; like all the systems that are currently not/only partially implemented as well.

    As of now it merely adds the seconds without converting them to minutes when in sugarcube 1x. Last resort I will just revert to my long hand method again lol
    Alianna wrote: »
    Hi, if it's a time format you want to use,

    Give a look to this thread : maybe you will find what you need :
    https://twinery.org/forum/discussion/3195/clocks-still-driving-me-nuts/p1

    Have a good day.

    Hey thanks for the link Alianna :) unfortunately it's not quite what I'm looking for because I require a more precise manner of timekeeping with more heavy emphasis on seconds and minutes; I'm even thinking of incorporating fractions of a second/milliseconds down the line!

    I appreciate the link anyway, perhaps I may be able to use something from it down the line but due to the fact that it is javascript it would likely be taxing for me to try to integrate with other systems as well. But thank you anyway :)
  • edited April 30
    RaddersHQ wrote: »
    I did notice whilst testing that this particular script will only work whilst using Sugarcube 2x.. Is there any possibility that a variation of this could be ported to work with sugarcube 1? I've been trying to leave the consideration of whether I want to transition or not till last seeing as how Sugarcube 2 makes some rather radical changes to the stylesheet (media screen, font, text size, layout, etcetera) along with other minute differences, so I haven't been all that keen to switch over just yet, largely in part due to the fact that I have so many other concerns; like all the systems that are currently not/only partially implemented as well.

    As of now it merely adds the seconds without converting them to minutes when in sugarcube 1x. Last resort I will just revert to my long hand method again lol

    I can't seem to get Twine 2 to load right now, so I can't test it, but I suspect it isn't working in SugarCube 1 because of the temp variable. Try changing _op to $op.
  • edited April 30
    RaddersHQ wrote: »
    ...only work whilst using Sugarcube 2x.
    The widget is using a temporary variable:
    <<set _op to Math.trunc($seconds / 60)>>
    ...
    <<set _op to Math.trunc($minutes / 60)>>
    ...
    <<set _op to Math.trunc($hour / 24)>>
    
    ... which are only available in the v2.x series, simply changing it to a story variable will allow it to work in both series (v1.x and v2.x) but will result in that variable being tracked by the History system.
  • Chapel wrote: »
    I can't seem to get Twine 2 to load right now, so I can't test it, but I suspect it isn't working in SugarCube 1 because of the temp variable. Try changing _op to $op.

    Sorry to hear about your twine not working! Tried that just now and no dice unfortunately, but what was interesting was that it seemed to be operating much the same in sugarcube 2x with both _ and $ prefixes tested individually.
    greyelf wrote: »
    RaddersHQ wrote: »
    ...only work whilst using Sugarcube 2x.
    The widget is using a temporary variable:
    <<set _op to Math.trunc($seconds / 60)>>
    ...
    <<set _op to Math.trunc($minutes / 60)>>
    ...
    <<set _op to Math.trunc($hour / 24)>>
    
    ... which are only available in the v2.x series, simply changing it to a story variable will allow it to work in both series (v1.x and v2.x) but will result in that variable being tracked by the History system.

    Story variable? I'm not quite sure what might constitute as a story variable exactly.. What would be the difference in formatting from a temporary variable to a story variable?
    greyelf wrote: »
    History system.

    You mean the system which keeps track of all the individual data throughout the story right? As long as time is affected by loading the game (reverting previous times etc) and the + seconds macro, then it shouldn't be too much of an issue unless it is DRASTICALLY different to the temp variable system, but as of right now I really have no idea.. It's the first time I've heard about such a dynamic as temporary variables/story variables to be honest.
  • edited May 3
    RaddersHQ wrote: »
    Sorry to hear about your twine not working! Tried that just now and no dice unfortunately, but what was interesting was that it seemed to be operating much the same in sugarcube 2x with both _ and $ prefixes tested individually.
    I just tested it and it worked--did you change all instances of _op to $op? Anyway, here's the widget rewritten for SugarCube 1. It will also be compatible with SugarCube 2.
    ::timeWidget [widget]
    <<widget "timeFormat">>\
      <<silently>>
        <<set $op to 0>>
        
        <<if $seconds gte 60>>
          <<set $op to Math.trunc($seconds / 60)>>
          <<set $minutes to $minutes + $op>>
          <<set $seconds to $seconds - ($op * 60)>>
        <</if>>
        
        <<if $minutes gte 60>>
          <<set $op to Math.trunc($minutes / 60)>>
          <<set $hour to $hour + $op>>
          <<set $minutes to $minutes - ($op * 60)>>
        <</if>>
        
        <<if $hour gte 24>>
          <<set $op to Math.trunc($hour / 24)>>
          <<set $day to $day + $op>>
          <<set $hour to $hour - ($op * 24)>>
        <</if>>
        
        <<unset $op>>
      <</silently>>\
    <</widget>>
    

    I tested it in SugarCube 1.0.34, and it seemed to work exactly the same as the version written for 2.x.
    RaddersHQ wrote: »
    You mean the system which keeps track of all the individual data throughout the story right? As long as time is affected by loading the game (reverting previous times etc) and the + seconds macro, then it shouldn't be too much of an issue unless it is DRASTICALLY different to the temp variable system, but as of right now I really have no idea.. It's the first time I've heard about such a dynamic as temporary variables/story variables to be honest.

    Temporary variables (_var) are not tracked by the history system, meaning they only exist for the "turn" they are created for--usually meaning that a passage navigation unsets them. Having lots and lots of story variables ($var) can slow down your story as the history system will drag all of those variables (even ones you don't really need) and their values through the whole game. Generally, you don't want unnecessary variables clogging up the history.

    For example, if you need to know if the player has been to the "circus" passage, instead of slipping a variable in that passage <<set $visitedCircus to true>> and then testing it later <<if $visitedCircus>>, you'd be better off using the visited() function:
    <<if $visited('circus')>>
    

    Basically, it's a bad practice to create story variables you don't need. Temporary variables only last for the current moment in the history, though, so they're fine.

    In this widget I used <<unset>> to prevent the story variable $op from being part of the history, which is functionally the same as using a temporary variable.
  • edited May 4
    RaddersHQ wrote: »
    Story variable
    The Twine documentation defines what a (story) variable is and how to name them. The link (named temporary variable) I included in my previous comment leads to the SugarCube v2.x Variables documentation which extends that definition to include it's temporary variables and the differences between the two types of variables.

    RaddersHQ wrote: »
    You mean the system which keeps track of all the individual data throughout the story right?
    Yes.

    During passage traversal a 'copy' of the state of all known story variables is made, the original story variable state is associated with the previous passage and added to the History system, and the 'copy' is made available to the passage about to be shown.
  • Sorry it took me so long to get back to this message guys, I've been busy trying to become self employed and it's finally paid off! WOO! Anyway, with that out the way, let's get back to personal business lol
    Chapel wrote: »
    ::timeWidget [widget]
    <<widget "timeFormat">>\
      <<silently>>
        <<set $op to 0>>
        
        <<if $seconds gte 60>>
          <<set $op to Math.trunc($seconds / 60)>>
          <<set $minutes to $minutes + $op>>
          <<set $seconds to $seconds - ($op * 60)>>
        <</if>>
        
        <<if $minutes gte 60>>
          <<set $op to Math.trunc($minutes / 60)>>
          <<set $hour to $hour + $op>>
          <<set $minutes to $minutes - ($op * 60)>>
        <</if>>
        
        <<if $hour gte 24>>
          <<set $op to Math.trunc($hour / 24)>>
          <<set $day to $day + $op>>
          <<set $hour to $hour - ($op * 24)>>
        <</if>>
        
        <<unset $op>>
      <</silently>>\
    <</widget>>
    

    Bloody hell, this is beautiful! I'm not quite sure how the '$op' works in this sense.. How are the variables not being reset after every passage transition if the '$op' is being unset at the end of this script? I'm guessing it's probably my limited understanding of the math.trunc macros to be fair, heh, which brings me to the question of what even is the function of the $op in this circumstance?

    Just trying to get a better understanding of the code involved so I can replicate something similar or truncate this system in the future. Thanks again for it by the way, seems to be doing the job!
    Chapel wrote: »
    I tested it in SugarCube 1.0.34, and it seemed to work exactly the same as the version written for 2.x.

    And yes, truthfully I didn't replace the underscore with the dollar sign when I was testing as I wasn't sure as to whether the underscores where specifically set in place for that reason (but if the '$' function exactly the same as the '_' then what point is there in having both? I'm guessing there must be *SOME* difference besides keystroke..)
    Chapel wrote: »

    Temporary variables (_var) are not tracked by the history system, meaning they only exist for the "turn" they are created for--usually meaning that a passage navigation unsets them. Having lots and lots of story variables ($var) can slow down your story as the history system will drag all of those variables (even ones you don't really need) and their values through the whole game. Generally, you don't want unnecessary variables clogging up the history.

    For example, if you need to know if the player has been to the "circus" passage, instead of slipping a variable in that passage <<set $visitedCircus to true>> and then testing it later <<if $visitedCircus>>, you'd be better off using the visited() function:
    <<if $visited('circus')>>
    

    Basically, it's a bad practice to create story variables you don't need. Temporary variables only last for the current moment in the history, though, so they're fine.

    Interesting.. See I was not aware of this either, but It is definitely good that I now know. I've got a lot of $set variables in my story that are as simple as 'which response did you pick and here's the answer and it probably won't get brought up ever again' so this could be very useful provided I can get my number-blind head around it! I really can't thank you enough by the way, this has all been extremely useful!
    In this widget I used <<unset>> to prevent the story variable $op from being part of the history, which is functionally the same as using a temporary variable.

    So it really is simple as that? I've got plenty of them as well so maybe I shouldn't be so worried. Just seemed daft to have all those metaphorical taps running when they're no longer serving a purpose.

    In this instance timekeeping will probably need to be a part of the history for the sake of loading the game, making sure variables are set in place, or even reverting the time back to a previous state if need be, so I think I will most likely need to remove that unset there. Going back to one of my previous posts, I'm still at a loss at how the $op variable even works atm lol
    greyelf wrote: »
    The Twine documentation defines what a (story) variable is and how to name them. The link (named temporary variable) I included in my previous comment leads to the SugarCube v2.x Variables documentation which extends that definition to include it's temporary variables and the differences between the two types of variables.

    Ahh, thank you! Seems like the only things I don't really already know are the various different terminologies for each macros/script and/or how they're properly referred to. Nice. Good to know so that I don't make a fool of myself whenever I'm trying to sound like I know what I'm doing lol, but with coding it really is something I'm still not fully acquainted with yet.

    greyelf wrote: »
    Yes.

    During passage traversal a 'copy' of the state of all known story variables is made, the original story variable state is associated with the previous passage and added to the History system, and the 'copy' is made available to the passage about to be shown.

    Nice. Appreciate the detail! Thank you
  • edited May 18
    About the $op variable, it does nothing. You don't need to worry about removing the <<unset>>; the other variables--everything important--will be a part of the history.

    I'm only using the _op and $op variables to store a bit of information to make the math more readable. I could instead write:
    <<if $seconds gte 60>>
          <<set $minutes += Math.trunc($seconds / 60)>>
          <<set $seconds to $seconds % 60>>
    <</if>>
    

    or something. It was just easier for my brain to stash that information, and I though it made it easier to understand. Clearly it did not do that latter part. _op/$op does nothing of consequence, and will get rewritten by new values as soon as the widget is called again anyway; you don't need that value to be stored.
  • @RaddersHQ: The Math.trunc() function belongs to the Javascript programming language that comes with your web-browser, it is one of the languages that SugarCube itself is written in.
  • Chapel wrote: »
    About the $op variable, it does nothing. You don't need to worry about removing the <<unset>>; the other variables--everything important--will be a part of the history.

    I'm only using the _op and $op variables to store a bit of information to make the math more readable. I could instead write:
    <<if $seconds gte 60>>
          <<set $minutes += Math.trunc($seconds / 60)>>
          <<set $seconds to $seconds % 60>>
    <</if>>
    

    or something. It was just easier for my brain to stash that information, and I though it made it easier to understand. Clearly it did not do that latter part. _op/$op does nothing of consequence, and will get rewritten by new values as soon as the widget is called again anyway; you don't need that value to be stored.

    Ahh. Thanks for clearing that up. I did a little bit of experimentation with the macros and managed to get it to work with milliseconds and even individual months! I suppose then that the <i>Math.trunc</i> is doing all the work? It's really quite impressive tbh, hopefully I will have mastered it soon but until then I'll probably just pick it up again when I need it.. Thanks again by the way :)
    greyelf wrote: »
    @RaddersHQ: The Math.trunc() function belongs to the Javascript programming language that comes with your web-browser, it is one of the languages that SugarCube itself is written in.

    I'm not a master of Javascript, and in fact I'm very grateful that the code used in twine is simple macros, which seems to be a lot easier to understand and comprehend than doing all the coding longhand.. Perhaps one day I should delve a bit further to increase my understanding. Until then though I'll carry on trying to finish this thing heh.. Thanks again btw :)
Sign In or Register to comment.