Howdy, Stranger!

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

Set of widgets controlling time, date and season I'm working on. Opinions appreciated.

edited June 2015 in Workshop
A first shot at creating a set of widgets to help smooth time advancement in an open-world rpg I want to create. The general layout on the page is something like this:
<<nobr>>
<<set $advanceminutes to x>>
<<set $advancemonth to y>>
<<etc>>
<<advancetime>>
<</nobr>>

Page Text Goes Here

<<printtime>>

I'm having some issues with white space still, and I'm sure the code isn't as streamlined as it could be. Sorry it's kinda ugly, I'm new-ish to this xP


<!--Weekday Widget-->
<<widget weekday>><<nobr>><<if $weekday eq 1>>Mon<<elseif $weekday eq 2>>Tue<<elseif $weekday eq 3>>Wed<<elseif $weekday eq 4>>Thu<<elseif $weekday eq 5>>Fri<<elseif $weekday eq 6>>Sat<<elseif $weekday eq 7>>Sun<</if>><</nobr>><</widget>>

<!--Month Widget-->
<<widget month>><<nobr>><<if $month eq 1>>JAN<<elseif $month eq 2>>FEB<<elseif $month eq 3>>MAR<<elseif $month eq 4>>APR<<elseif $month eq 5>>MAY<<elseif $month eq 6>>JUN<<elseif $month eq 7>>JUL<<elseif $month eq 8>>AUG<<elseif $month eq 9>>SEP<<elseif $month eq 10>>OCT<<elseif $month eq 11>>NOV<<elseif $month eq 12>>Dec<</if>><</nobr>><</widget>>

<!--Season Widget-->
<<widget season>><<nobr>><<if $month gte 1 and $month lte 3>>Spring<<elseif $month gte 4 and $month lte 6>>Summer<<elseif $month gte 7 and $month lte 9>>Fall<<elseif $month gte 10 and $month lte 12>>Winter<</if>><</nobr>><</widget>>

<!--Time Advancement Widget-->
<<widget advancetime>><<nobr>>
<!--Advance Minutes-->
<<if $advanceminutes gt 0>>
	<<set $minutes to $minutes + $advanceminutes>>
<</if>>
<<if $minutes gt 59>>
	<<set $minutes to $minutes - 59>>
    <<set $advancehour to $advancehour + 1>>
<</if>>
<!--Advance Hour-->
<<if $advancehour gt 0>>
	<<set $hour to $hour + $advancehour>>
<</if>>
<<if $hour gt 24>>
	<<set $hour to $hour - 24>>
    <<set $advanceday to $advanceday + 1>>
<</if>>
<!--Advance Day-->
<<if $advanceday gt 0>>
	<<set $day to $day + $advanceday>>
    <<set $weekday to $weekday + $advanceday>>
<</if>>
<<if $day gt 30>>
	<<set $day to $day - 30>>
    <<set $advancemonth to $advancemonth + 1>>
<</if>>
<<if $weekday gt 7>>
	<<set $weekday to $weekday - 7>>
    <<if $weekday gt 7>>
    	<<set $weekday to $weekday - 7>>
        <<if $weekday gt 7>>
        	<<set $weekday to $weekday - 7>>
            <<if $weekday gt 7>>
            	<<set $weekday to $weekday - 7>>
            <</if>>
        <</if>>
    <</if>>
<</if>>
<!--Advance Month-->
<<if $advancemonth gt 0>>
	<<set $month to $month + $advancemonth>>
<</if>>
<<if $month gt 12>>
	<<set $month to $month - 12>>
    <<set $advanceyear to $advanceyear + 1>>
<</if>> 
<!--Advance Year-->
<<if $advanceyear gt 0>>
	<<set $year to $year + $advanceyear>>
<</if>>
<<set $advanceminutes to 0>>
<<set $advancehour to 0>>
<<set $advanceday to 0>>
<<set $advancemonth to 0>>
<<set $advanceyear to 0>>
<</nobr>>
<</widget>>
<!--Printing Widget>
<<widget printtime>>
<<print $hour>>:<<if $minutes lt 10>>0<</if>><<print $minutes>>
<<weekday>> <<month>> <<print $day>> <<season>> of <<print $year>>
<</widget>>


Edited because I accidentally left out a couple of the widgets. They're kind of important so I popped em in.

Comments

  • Why the repetition?
    <<if $weekday gt 7>>
    	<<set $weekday to $weekday - 7>>
        <<if $weekday gt 7>>
        	<<set $weekday to $weekday - 7>>
            <<if $weekday gt 7>>
            	<<set $weekday to $weekday - 7>>
                <<if $weekday gt 7>>
                	<<set $weekday to $weekday - 7>>
                <</if>>
            <</if>>
        <</if>>
    <</if>>
    
  • That is there so I can advance the days by any amount under a month and still have a weekday associated with it. For instance, if I just had that code run one time, and I advanced by say 29 days, and the current date was Monday the 1st of whatever, it would come back as the 30th of whatever, but the weekday widget would be trying to find a value for 22, which it doesn't have. So I put in enough repetitions to enable it to convert any advancement up to 35 days in to a 1-7 value that it can look up on the weekday chart. Any value over that I would just use advancemonth and advancedays. I hope that is a clear explanation. As I said, I'm new, and there might be a more efficient way to do it, but that seemed best with the knowledge I have.
  • This is really cool and exactly what i tried to create myself. Although i am not so good with programming. Is this for twine 1.4 or 2.0? also is it possible to get permission to use this? ofc with credits :D
  • The above widgets were written for the SugarCube story format (the only one that supports widgets) and that story format works in both Twine 1.x and 2.x.
  • edited July 2015
    Thanks for the hard work Eddies. When I click 'Play' I get an Unexpected Token error during the initializing, so the game doesn't load. This is with me just dragging the code to the Edit Story Java area. Is this because the time isn't set yet, or is another step needed? I'm a novice, so I'm guessing this is something simple that I just don't know about yet.

    Once again all of you are great and this calendar looks brilliant- I love that you did seasons too...
  • JavaScript (Java and JavaScript are not related, except by name similarity).

    You don't put widgets in the Story JavaScript, they go in a normal passage which should be tagged widget.
  • Pfft... that's a riot. I would've NEVER figured that out on my own. Knew it was something obvious to everyone else since no one else asked. Figured it just needed a <<Int>> command or something to turn it on.

    Sounds like saying English and English Subtitles aren't related, lol.

    Thanks again Mad.
  • Coupla things that might help:

    Modula arithmetic -
    <<set $weekday to $weekday % 7>>
    
    - gives a 0-6 value, you can add 1 if you want. For integer division you need
    Math.floor(a/b)
    
    , so:
    <<set $advanceyear to $advanceyear + Math.floor($advancemonth/12)>>
    <<set $advancemonth to $advancemonth % 12>>
    

    Arrays -
    <<set $weekdays to [ "Mon", "Tue", "Wed", "thr", "fri", "Sat", "Sun"]>> 
    
    <<widget weekday>><<nobr>><<print $weekdays[$weekday]>><</nobr>><</widget>>
    

    ...assuming I've got the widget syntax right. Needs a 0-6 value for weekday.
  • I went about creating the same thing you are doing now. Then I was kindly informed javascript has a built-in Date class.
  • ...which is fine if you want an earth normal year...
  • Sorry I took so long to check this. Just moved out of state, so things have been kinda hectic. Mykael, thanks for the suggestions, that is definitely cleaner than what I was doing. I found the date class when I went searching to see if anyone else had posted anything like this around before, but as Mykael said, it only works for the Gregorian calendar we use, which isn't what I wanted. Zhidori, you are more than welcome to use it :).
Sign In or Register to comment.