Real World Time

Hey all!

I could have sworn there was a thread on this before, but I can't seem to find it. I was wondering if there was a way to have my game keep track of real world time like Months and Days. That way, I can set up a way for Holidays to be automatically activated and disabled. Same for weather too. :) Anyone have any ideas?

Anonynn.


The thread, The Date, started just three hours before this one shows the basics.


The JS:

var today = new Date();
var dd = today.getDate();
var mm = today.getMonth()+1;
var yyyy = today.getFullYear();
var hrs = today.getHours();
var mins = today.getMinutes();
var secs = today.getSeconds();
if(dd<10) {
	dd = '0'+dd
} 
if(mm<10) {
	mm = '0'+mm
} 
today = mm + '/' + dd + '/' + yyyy;
if(hrs>12) {
	ampm = 'am';
	hrs = '0' + '' + hrs - 12
}else{
	ampm = 'pm'
} 
if (mins<10) {
	mins = '0'+mins
} 
if(secs<10) {secs = '0' + secs}
time = hrs + ':' + mins + ':' + secs + ' ' + ampm;
ASLEvent('SetDate',today);
ASLEvent('SetTime',time);

Now, the easiest way to use JS without creating/needing a separate JS file, is to use JS.eval(). So, we just make that code inline (remove all the new lines from the script), and wrap it with JS.eval("code here"). Like so:

JS.eval("var today = new Date();var dd = today.getDate();var mm = today.getMonth()+1;var yyyy = today.getFullYear();var hrs = today.getHours();var mins = today.getMinutes();var secs = today.getSeconds();if(dd<10) {	dd = '0'+dd} if(mm<10) {	mm = '0'+mm} today = mm + '/' + dd + '/' + yyyy;if(hrs>12) {	ampm = 'am';	hrs = '0' + '' + hrs - 12}else{	ampm = 'pm'} if (mins<10) {	mins = '0'+mins} if(secs<10) {secs = '0' + secs}time = hrs + ':' + mins + ':' + secs + ' ' + ampm;ASLEvent('SetDate',today);ASLEvent('SetTime',time);")

I like to create a function in Quest that runs that JS script, so I only have to enter it once. (I call it TimeAndDate().)


The only three functions you really need to add to Quest:

  <function name="SetDate" parameters="today">
    game.todaysdate = today
  </function>
  <function name="SetTime" parameters="time">
    game.timefromJS = time
  </function>
  <function name="SetTimeAndDate"><![CDATA[
    JS.eval ("var today = new Date();var dd = today.getDate();var mm = today.getMonth()+1;var yyyy = today.getFullYear();var hrs = today.getHours();var mins = today.getMinutes();var secs = today.getSeconds();if(dd<10) {	dd = '0'+dd} if(mm<10) {	mm = '0'+mm} today = mm + '/' + dd + '/' + yyyy;if(hrs>12) {	ampm = 'am';	hrs = '0' + '' + hrs - 12}else{	ampm = 'pm'} if (mins<10) {	mins = '0'+mins} if(secs<10) {secs = '0' + secs}time = hrs + ':' + mins + ':' + secs + ' ' + ampm;ASLEvent('SetDate',today);ASLEvent('SetTime',time);")
  ]]></function>

The functions I add to make things easier:

  <function name="Time" type="string">
    return (game.timefromJS)
  </function>
  <function name="Date" type="string">
    return (game.todaysdate)
  </function>

A start script:

SetTimeAndDate
//The following is a test.
//I use a 2 second timeout to give Quest time to run the SetTimeAndDate script, especially its ASLEvents.
//  Otherwise, errors occur.
SetTimeout (2) {
  //NOTE that I use Date() instead of just Date.
  // When a function returns something, that's how you msg it.
  msg ("Welcome, Adventurer!<br/><br/>Today is "+ Date() +", and the time is now: "+ Time()+".  (That's hh:mm:ss, of course.)")
}
//NOTE: The SetTimeout() is only needed when you call SetTimeAndDate.
// If you are NOT calling SetTimeAndDate in the same script(or at the same time) \
//   you need no SetTimeout() to access Date() or Time().
//
// ALSO: You can just msg(game.todaysdate) or msg(game.timefromJS) instead of using Date() and Time().

So, let's say I wanted just like...

Month and Day, I don't need minutes or seconds. And how would I make a variable like this...

{if Date.January:It's currently very cold outside and snowing!} vs {if Date.May:It's currently very hot outside and raining!}

Or

{if Date.February} 
Valentine's Day=True
{if Date.October}
Hallow's Shroud=True

Something like that. Are these possible?

Anonynn.


<!--Saved by Quest 5.7.6404.15496-->
<asl version="550">
  <include ref="English.aslx" />
  <include ref="Core.aslx" />
  <game name="Set Holidays">
    <gameid>79c0b4c6-085f-4285-a2ac-a64763aabe83</gameid>
    <version>0.0.1</version>
    <firstpublished>2017</firstpublished>
    <inituserinterface type="script"><![CDATA[
      JS.eval ("var today = new Date();var dd = today.getDate();var mm = today.getMonth()+1;if(mm == 2 && dd == 14){ASLEvent('SetHoliday','Valentines');}else if(mm == 10 && dd == 31){ASLEvent('SetHoliday','Halloween');}else if(mm == 12 && dd == 28){ASLEvent('SetHoliday','SPECIAL');};")
    ]]></inituserinterface>
  </game>
  <object name="room">
    <inherit name="editor_room" />
    <beforeenter type="script">
      SetTimeout (2) {
        if (HasAttribute(game,"specialday")) {
          msg ("It's a special day!")
        }
      }
    </beforeenter>
    <object name="player">
      <inherit name="editor_object" />
      <inherit name="editor_player" />
    </object>
  </object>
  <function name="SetHoliday" parameters="holiday">
    switch (holiday) {
      case ("Halloween") {
        game.halloween = true
      }
      case ("Valentines") {
        game.valentines = true
      }
      case ("SPECIAL") {
        game.specialday = true
      }
    }
  </function>
</asl>

Here's an updated version that uses a string dictionary to return strings as messages on holidays:

<!--Saved by Quest 5.7.6404.15496-->
<asl version="550">
  <include ref="English.aslx" />
  <include ref="Core.aslx" />
  <game name="Set Holidays">
    <gameid>79c0b4c6-085f-4285-a2ac-a64763aabe83</gameid>
    <version>0.0.2</version>
    <firstpublished>2017</firstpublished>
    <inituserinterface type="script"><![CDATA[
      JS.eval ("var today = new Date();var dd = today.getDate();var mm = today.getMonth()+1;if(mm == 2 && dd == 14){ASLEvent('SetHoliday','Valentines');}else if(mm == 10 && dd == 31){ASLEvent('SetHoliday','Halloween');}else if(mm == 12 && dd == 28){ASLEvent('SetHoliday','SPECIAL');};")
    ]]></inituserinterface>
    <object name="calendar">
      <inherit name="editor_object" />
      <dict type="stringdictionary">
        <item>
          <key>Halloween</key>
          <value>Hallow's Shroud</value>
        </item>
        <item>
          <key>Valentines</key>
          <value>Valentine's Day</value>
        </item>
        <item>
          <key>specialday</key>
          <value>Special</value>
        </item>
      </dict>
    </object>
  </game>
  <object name="room">
    <inherit name="editor_room" />
    <beforeenter type="script">
      SetTimeout (2) {
        if (HasAttribute(calendar,"specialday")) {
          msg ("It's a special day!")
        }
        foreach (key, calendar.dict) {
          if (GetBoolean(calendar,key)) {
            msg ("Welcome to the "+StringDictionaryItem(calendar.dict,key)+" Edition!")
          }
        }
      }
    </beforeenter>
    <object name="player">
      <inherit name="editor_object" />
      <inherit name="editor_player" />
    </object>
  </object>
  <function name="SetHoliday" parameters="holiday">
    switch (holiday) {
      case ("Halloween") {
        calendar.halloween = true
      }
      case ("Valentines") {
        calendar.valentines = true
      }
      case ("SPECIAL") {
        calendar.specialday = true
      }
    }
  </function>
</asl>

You can add whatever days you'd like to that dictionary.

Remember that you need to use == or === when checking values in JS.

= is only for setting variables or functions or what have you.

You could also check if the day was between, say the twentieth and twenty-fourth when you were in month 12 to display a Christmas countdown or something like that.

You can also just check for mm or dd, but it has to be in JS.eval() because they are JS variables. (You could make a function to set the month and a separate function to set the day, then call those with ASLEvents. Or you could get really crafty and use one script to separate the bits of the string you pass as a paramater. I'd stick with a function for each thing, though.)

Also remember to include that SetTimeout when you're doing something on game load (or at the same time you're checking the date).

In fact, 2 seconds might not be enough.

In FACT... I seem to remember Pixie using two, 2-second SetTimeouts (one nested inside the other) to make sure something actually got set before running another script. (It may not have been Pixie, but it seems like it was.)


Argh! So .......I'll need a bit of a walk-through on this.

So I have this function.

    <function name="SetHoliday" parameters="holiday">
	   switch (holiday) {
      case ("Hallow's Shroud") {
        game.hs = true
      }
      case ("Lover's Gala") {
        game.lg = true
      }
      case ("Feast of Fertility") {
        game.fof = true
      }
	   case ("Winter Repast") {
        game.wr = true
      }
    }
   </function>

Now I need to put this JS Script into the game. Right?

JS.eval ("var today = new Date();var dd = today.getDate();var mm = today.getMonth()+1;if(mm == 2 && dd == 14){ASLEvent('SetHoliday','Lover's Gala');}else if(mm == 10 && dd == 31){ASLEvent('SetHoliday','Hallow's Shroud');}else if(mm == 12 && dd == 28){ASLEvent('SetHoliday','Winter Repast');};")

^---- And I was wondering if something like this was possible (mm == 10 && dd == 15 && 31) like from October 15-31.

and would I be able to use this in the text processor?

{if Date.January:It's currently very cold outside and snowing!} vs {if Date.May:It's currently very hot outside and raining!} for example?

Anonynn

PS! Thanks for the help so far!


Err...

ASLEvent('SetHoliday','Hallow's Shroud')

I'd make that hallowsShroud to avoid syntax errors (because it's inside of JS.eval("ASLEvent('SetHoliday','Hallow's Shroud');") when you break it down, and that apostrophe in "Hallow's" may (or may not) cause an unexpected End Of File error). Like... it might work. Or it might need to be Hallow\'s Shroud... I'm not certain in this instance.


This if (mm == 10 && dd == 15 && 31)){ASLEvent('SetHoliday','hallowsShroud');}; would be more like:

if(mm == 10 && (15 < dd && dd < 31)){ASLEvent('SetHoliday','hallowsShroud');};

The text processor reads the values of the attributes of in-game objects, so you'd probably need to make a function to set the month.

<function name="SetMonth"  parameters="month">
  game.month = month
</function>

Then, after having set the date up in JS:

JS.eval("ASLEvent('SetMonth',mm);")

Finally (I'll use December, to make it work in the test):

{if game.month=12:It's currently very cold outside and snowing!}

Here's an example game, with only the month being set up:

<!--Saved by Quest 5.7.6404.15496-->
<asl version="550">
  <include ref="English.aslx" />
  <include ref="Core.aslx" />
  <game name="nnn">
    <gameid>113ae923-f8a2-4b92-a4a6-1af36ab0ba4c</gameid>
    <version>1.0</version>
    <firstpublished>2017</firstpublished>
    <start type="script">
      JS.eval ("var today = new Date();var dd = today.getDate();var mm = today.getMonth()+1;ASLEvent('SetMonth',mm);")
    </start>
  </game>
  <object name="room">
    <inherit name="editor_room" />
    <enter type="script"><![CDATA[
      JS.eval ("if(mm == 10 && (15 < dd && dd < 31)){alert('CHECK!');};")
    ]]></enter>
    <object name="player">
      <inherit name="editor_object" />
      <inherit name="editor_player" />
    </object>
    <object name="Brochure">
      <inherit name="editor_object" />
      <look>{if game.month=12:It's currently very cold outside and snowing!}</look>
    </object>
  </object>
  <function name="SetMonth" parameters="month">
    game.month = month
  </function>
</asl>

A little more technical:

<!--Saved by Quest 5.7.6404.15496-->
<asl version="550">
  <include ref="English.aslx" />
  <include ref="Core.aslx" />
  <game name="nnn">
    <gameid>113ae923-f8a2-4b92-a4a6-1af36ab0ba4c</gameid>
    <version>1.0</version>
    <firstpublished>2017</firstpublished>
    <start type="script"><![CDATA[
      JS.eval ("var today = new Date();var dd = today.getDate();var mm = today.getMonth()+1;ASLEvent('SetMonth',mm);ASLEvent('SetDay',dd);if(mm==12&&(dd>27&&dd<=31)){ASLEvent('SetHoliday','newYears');}")
    ]]></start>
  </game>
  <object name="room">
    <inherit name="editor_room" />
    <enter type="script"><![CDATA[
      JS.eval ("if(mm == 10 && (15 < dd && dd < 31)){alert('CHECK!');};")
    ]]></enter>
    <description><![CDATA[<hr/><br/>{once:The messages concerning the calendar will not print here because there hasn't been enough time for the JS function to pass the information to Quest through the ASLEvent(s).<br/><br/>{command:Examine the Brochure} or {command:in:leave the room} and come back in to see the actual message.<br/><br/>(NOTE:  If I'd used a script here, with a SetTimeout(2) before printing this message, it would probably work correctly.)<br/>}{notfirst:Now that everything has had time to be set up, the message will appear correctly.}<br/><hr/><br/><br/>{if calendar.month=12:It's currently very cold outside and snowing!}{if calendar.isHoliday:<br/><br/>{=HolidayMessage(calendar.holiday)}}]]></description>
    <object name="player">
      <inherit name="editor_object" />
      <inherit name="editor_player" />
    </object>
    <object name="Brochure">
      <inherit name="editor_object" />
      <look><![CDATA[{if calendar.month=12:It's currently very cold outside and snowing!}{if calendar.isHoliday:<br/><br/>{=HolidayMessage(calendar.holiday)}}]]></look>
    </object>
    <exit alias="in" to="another room">
      <inherit name="indirection" />
    </exit>
  </object>
  <object name="calendar">
    <inherit name="editor_object" />
    <holidays type="stringdictionary">
      <item>
        <key>valentines</key>
        <value>Insert Valentine's Day message here!</value>
      </item>
      <item>
        <key>easter</key>
        <value>INSERT EASTER EGGS ALERT HERE!</value>
      </item>
      <item>
        <key>stPatricks</key>
        <value>INSERT SAINT PATRICK'S DAY MESSAGE!</value>
      </item>
      <item>
        <key>hallowsShroud</key>
        <value>INSERT HALLOW'S SHROUD MESSAGE</value>
      </item>
      <item>
        <key>christmas</key>
        <value>INSERT XMAS MESSAGE</value>
      </item>
      <item>
        <key>newYears</key>
        <value>Have a happy new year!</value>
      </item>
    </holidays>
    <isHoliday type="boolean">false</isHoliday>
    <holiday type="string"></holiday>
  </object>
  <object name="another room">
    <inherit name="editor_room" />
    <description><![CDATA[This room is pointless.<br/><br/>{command:out:Go back to the first room.}]]></description>
    <exit alias="out" to="room">
      <inherit name="outdirection" />
    </exit>
  </object>
  <function name="SetMonth" parameters="month">
    calendar.month = month
  </function>
  <function name="HolidayMessage" parameters="holiday" type="string">
    return (StringDictionaryItem(calendar.holidays,holiday))
  </function>
  <function name="SetHoliday" parameters="holiday">
    calendar.isHoliday = true
    calendar.holiday = holiday
  </function>
  <function name="SetDay" parameters="day">
    calendar.day = day
  </function>
</asl>

Actually, I may need to think about this a little because I already have a day/night cycle in the game when you move or rest. The time is divided into 4 quarters.

Morning
Afternoon
Evening
Night

So I guess I need an in-game calendar or something with the same premise. Like when you start off in the beginning, the game sets your current IRL day and month into the in-game calendar. Then from there the game's passing time would take over. For example, if you download the game in December and then open it to play it, the in-game calendar gets set to "December 28". Then as you play and go through the day/night cycle time would advance.

Is that making sense?

These two functions should still work, I think.

    <function name="SetHoliday" parameters="holiday">
	   switch (holiday) {
      case ("hallowsShroud") {
        game.hs = true
      }
      case ("loversGala") {
        game.lg = true
      }
      case ("feastofFertility") {
        game.fof = true
      }
	   case ("winterRepast") {
        game.wr = true
      }
    }
   </function>
   
   <function name="SetMonth"  parameters="month">
  game.month = month
</function>

But this might need to be modified. It should set the REAL day and month, and then we need to create an in-game calendar. Sorry x_X I should have taken that into account right in the beginning.

JS.eval ("var today = new Date();var dd = today.getDate();var mm = today.getMonth()+1;if(mm == 2 && (1 < dd && dd < 20)){ASLEvent('SetHoliday','loversGala');}else if(mm == 10 &&(15 < dd && dd < 31)){ASLEvent('SetHoliday','hallowsShroud');}else if(mm == 12 && (15 < dd && dd < 30)){ASLEvent('SetHoliday','winterRepast');};")else if(mm == 4 && (1 < dd && dd < 15)){ASLEvent('SetHoliday','feastofFertility');};")

and the Start Script might need to be modified.

JS.eval ("var today = new Date();var dd = today.getDate();var mm = today.getMonth()+1;ASLEvent('SetMonth',mm);")

I can explain what I mean further if I'm not making sense.


Wait, wait...

All I had in the end was the day, month, and if it was a holiday:

<function name="SetMonth" parameters="month">
    calendar.month = month
  </function>

  <function name="HolidayMessage" parameters="holiday" type="string">
    return (StringDictionaryItem(calendar.holidays,holiday))
  </function>

  <function name="SetHoliday" parameters="holiday">
    calendar.isHoliday = true
    calendar.holiday = holiday
  </function>

  <function name="SetDay" parameters="day">
    calendar.day = day
  </function>

and it had a calendar:

  <object name="calendar">
    <inherit name="editor_object" />
    <holidays type="stringdictionary">
      <item>
        <key>valentines</key>
        <value>Insert Valentine's Day message here!</value>
      </item>
      <item>
        <key>easter</key>
        <value>INSERT EASTER EGGS ALERT HERE!</value>
      </item>
      <item>
        <key>stPatricks</key>
        <value>INSERT SAINT PATRICK'S DAY MESSAGE!</value>
      </item>
      <item>
        <key>hallowsShroud</key>
        <value>INSERT HALLOW'S SHROUD MESSAGE</value>
      </item>
      <item>
        <key>christmas</key>
        <value>INSERT XMAS MESSAGE</value>
      </item>
      <item>
        <key>newYears</key>
        <value>Have a happy new year!</value>
      </item>
    </holidays>
    <isHoliday type="boolean">false</isHoliday>
    <holiday type="string"></holiday>
  </object>

Are you just wanting to increase game.day by 1 when the game changes from Night to Morning?


I'm confused, but I think a short break is all I need.

(Be right back. Bwahahahaha!)


Okay...

Check it out!

I have accessed the local weather and set up attributes:

UPDATED

image


image


//UPDATED 2am CST
<!--Saved by Quest 5.7.6404.15496-->
<asl version="550">
  <include ref="English.aslx" />
  <include ref="Core.aslx" />
  <game name="nnn">
    <gameid>113ae923-f8a2-4b92-a4a6-1af36ab0ba4c</gameid>
    <version>1.0</version>
    <firstpublished>2017</firstpublished>
    <feature_annotations />
    <attr name="feature_advancedwearables" type="boolean">false</attr>
    <feature_advancedscripts />
    <start type="script"><![CDATA[
      calendar.weatherCodeDict = NewStringDictionary()
      dictionary add (calendar.weatherCodeDict, "0", "tornado")
      dictionary add (calendar.weatherCodeDict, "1", "tropical storm")
      dictionary add (calendar.weatherCodeDict, "2", "hurricane")
      dictionary add (calendar.weatherCodeDict, "3", "severe thunderstorms")
      dictionary add (calendar.weatherCodeDict, "4", "thunderstorms")
      dictionary add (calendar.weatherCodeDict, "5", "mixed rain and snow")
      dictionary add (calendar.weatherCodeDict, "6", "mixed rain and sleet")
      dictionary add (calendar.weatherCodeDict, "7", "mixed snow and sleet")
      dictionary add (calendar.weatherCodeDict, "8", "freezing drizzle")
      dictionary add (calendar.weatherCodeDict, "9", "drizzle")
      dictionary add (calendar.weatherCodeDict, "10", "freezing rain")
      dictionary add (calendar.weatherCodeDict, "11", "showers")
      dictionary add (calendar.weatherCodeDict, "12", "showers")
      dictionary add (calendar.weatherCodeDict, "13", "snow flurries")
      dictionary add (calendar.weatherCodeDict, "14", "light snow showers")
      dictionary add (calendar.weatherCodeDict, "15", "blowing snow")
      dictionary add (calendar.weatherCodeDict, "16", "snow")
      dictionary add (calendar.weatherCodeDict, "17", "hail")
      dictionary add (calendar.weatherCodeDict, "18", "sleet")
      dictionary add (calendar.weatherCodeDict, "19", "dust")
      dictionary add (calendar.weatherCodeDict, "20", "foggy")
      dictionary add (calendar.weatherCodeDict, "21", "haze")
      dictionary add (calendar.weatherCodeDict, "22", "smoky")
      dictionary add (calendar.weatherCodeDict, "23", "blustery")
      dictionary add (calendar.weatherCodeDict, "24", "windy")
      dictionary add (calendar.weatherCodeDict, "25", "cold")
      dictionary add (calendar.weatherCodeDict, "26", "cloudy")
      dictionary add (calendar.weatherCodeDict, "27", "mostly cloudy")
      dictionary add (calendar.weatherCodeDict, "28", "mostly cloudy")
      dictionary add (calendar.weatherCodeDict, "29", "partly cloudy")
      dictionary add (calendar.weatherCodeDict, "30", "partly cloudy")
      dictionary add (calendar.weatherCodeDict, "31", "clear")
      dictionary add (calendar.weatherCodeDict, "32", "sunny")
      dictionary add (calendar.weatherCodeDict, "33", "fair")
      dictionary add (calendar.weatherCodeDict, "34", "fair")
      dictionary add (calendar.weatherCodeDict, "35", "mixed rain and hail")
      dictionary add (calendar.weatherCodeDict, "36", "hot")
      dictionary add (calendar.weatherCodeDict, "37", "isolated thunderstorms")
      dictionary add (calendar.weatherCodeDict, "38", "scattered thunderstorms")
      dictionary add (calendar.weatherCodeDict, "39", "scattered thunderstorms")
      dictionary add (calendar.weatherCodeDict, "40", "scattered showers")
      dictionary add (calendar.weatherCodeDict, "41", "heavy snow")
      dictionary add (calendar.weatherCodeDict, "42", "scattered snow showers")
      dictionary add (calendar.weatherCodeDict, "43", "heavy snow")
      dictionary add (calendar.weatherCodeDict, "44", "partly cloudy")
      dictionary add (calendar.weatherCodeDict, "45", "thundershowers")
      dictionary add (calendar.weatherCodeDict, "46", "snow showers")
      dictionary add (calendar.weatherCodeDict, "47", "isolated thundershowers")
      dictionary add (calendar.weatherCodeDict, "3200", "not available")
      // JS.eval (js_room.description)
      JS.eval ("var today = new Date();var yy = today.getYear()+1900;var dd = today.getDate();var mm = today.getMonth()+1;ASLEvent('SetYear',yy);ASLEvent('SetMonth',mm);ASLEvent('SetDay',dd);if(mm==12&&(dd>27&&dd<=31)){ASLEvent('SetHoliday','newYears');};")
    ]]></start>
    <inituserinterface type="script">
    </inituserinterface>
    <object name="startupRoom">
      <inherit name="editor_room" />
      <enter type="script">
        ClearScreen
        msg ("Please enter the name of the city in which you are currently located.")
        get input {
          SetCityManually (result)
          msg ("Setting city to "+result+".")
          JS.eval (js_room.description)
          SetTimeout (2) {
            JS.loadWeather (calendar.playerCity)
          }
          SetTimeout (4) {
            ClearScreen
            MoveObject (game.pov, room)
            JS.loadWeather (calendar.playerCity)
          }
        }
      </enter>
      <object name="player">
        <inherit name="editor_object" />
        <inherit name="editor_player" />
      </object>
    </object>
  </game>
  <object name="room">
    <inherit name="editor_room" />
    <description><![CDATA[<hr/><br/>Today is {calendar.month}-{calendar.day}-{calendar.year}.<br/><hr/><br/><br/>It is {calendar.tempF}&deg;F and {=WeatherStatus(calendar.weatherCode)} outside!{if calendar.isHoliday:<br/><br/>{=HolidayMessage(calendar.holiday)}}<br/><br/><div id='weather'></div>]]></description>
    <enter type="script"><![CDATA[
      JS.eval ("if(mm == 10 && (15 < dd && dd < 31)){alert('CHECK!');};")
    ]]></enter>
    <object name="Brochure">
      <inherit name="editor_object" />
      <look><![CDATA[It is {calendar.tempF}&deg;F and {=WeatherStatus(calendar.weatherCode)} outside!{if calendar.isHoliday:<br/><br/>{=HolidayMessage(calendar.holiday)}}]]></look>
    </object>
    <exit alias="in" to="another room">
      <inherit name="indirection" />
    </exit>
  </object>
  <object name="calendar">
    <inherit name="editor_object" />
    <holidays type="stringdictionary">
      <item>
        <key>valentines</key>
        <value>Insert Valentine's Day message here!</value>
      </item>
      <item>
        <key>easter</key>
        <value>INSERT EASTER EGGS ALERT HERE!</value>
      </item>
      <item>
        <key>stPatricks</key>
        <value>INSERT SAINT PATRICK'S DAY MESSAGE!</value>
      </item>
      <item>
        <key>hallowsShroud</key>
        <value>INSERT HALLOW'S SHROUD MESSAGE</value>
      </item>
      <item>
        <key>christmas</key>
        <value>INSERT XMAS MESSAGE</value>
      </item>
      <item>
        <key>newYears</key>
        <value>We hope you have a happy and safe new year!</value>
      </item>
    </holidays>
    <isHoliday type="boolean">false</isHoliday>
    <holiday type="string"></holiday>
  </object>
  <object name="another room">
    <inherit name="editor_room" />
    <description><![CDATA[This room is pointless.<br/><br/>{command:out:Go back to the first room.}]]></description>
    <exit alias="out" to="room">
      <inherit name="outdirection" />
    </exit>
  </object>
  <object name="js_room">
    <inherit name="editor_room" />
    <description><![CDATA[/*! simpleWeather v3.1.0 - http://simpleweatherjs.com */!function(t){"use strict";function e(t,e){return"f"===t?Math.round(5/9*(e-32)):Math.round(1.8*e+32)}t.extend({simpleWeather:function(i){i=t.extend({location:"",woeid:"",unit:"f",success:function(t){},error:function(t){}},i);var o=new Date,n="https://query.yahooapis.com/v1/public/yql?format=json&rnd="+o.getFullYear()+o.getMonth()+o.getDay()+o.getHours()+"&diagnostics=true&callback=?&q=";if(""!==i.location){var r="";r=/^(\-?\d+(\.\d+)?),\s*(\-?\d+(\.\d+)?)$/.test(i.location)?"("+i.location+")":i.location,n+='select * from weather.forecast where woeid in (select woeid from geo.places(1) where text="'+r+'") and u="'+i.unit+'"'}else{if(""===i.woeid)return i.error("Could not retrieve weather due to an invalid location."),!1;n+="select * from weather.forecast where woeid="+i.woeid+' and u="'+i.unit+'"'}return t.getJSON(encodeURI(n),function(t){if(null!==t&&null!==t.query&&null!==t.query.results&&"Yahoo! Weather Error"!==t.query.results.channel.description){var o,n=t.query.results.channel,r={},s=["N","NNE","NE","ENE","E","ESE","SE","SSE","S","SSW","SW","WSW","W","WNW","NW","NNW","N"],a="https://s.yimg.com/os/mit/media/m/weather/images/icons/l/44d-100567.png";r.title=n.item.title,r.temp=n.item.condition.temp,r.code=n.item.condition.code,r.todayCode=n.item.forecast[0].code,r.currently=n.item.condition.text,r.high=n.item.forecast[0].high,r.low=n.item.forecast[0].low,r.text=n.item.forecast[0].text,r.humidity=n.atmosphere.humidity,r.pressure=n.atmosphere.pressure,r.rising=n.atmosphere.rising,r.visibility=n.atmosphere.visibility,r.sunrise=n.astronomy.sunrise,r.sunset=n.astronomy.sunset,r.description=n.item.description,r.city=n.location.city,r.country=n.location.country,r.region=n.location.region,r.updated=n.item.pubDate,r.link=n.item.link,r.units={temp:n.units.temperature,distance:n.units.distance,pressure:n.units.pressure,speed:n.units.speed},r.wind={chill:n.wind.chill,direction:s[Math.round(n.wind.direction/22.5)],speed:n.wind.speed},n.item.condition.temp<80&&n.atmosphere.humidity<40?r.heatindex=-42.379+2.04901523*n.item.condition.temp+10.14333127*n.atmosphere.humidity-.22475541*n.item.condition.temp*n.atmosphere.humidity-6.83783*Math.pow(10,-3)*Math.pow(n.item.condition.temp,2)-5.481717*Math.pow(10,-2)*Math.pow(n.atmosphere.humidity,2)+1.22874*Math.pow(10,-3)*Math.pow(n.item.condition.temp,2)*n.atmosphere.humidity+8.5282*Math.pow(10,-4)*n.item.condition.temp*Math.pow(n.atmosphere.humidity,2)-1.99*Math.pow(10,-6)*Math.pow(n.item.condition.temp,2)*Math.pow(n.atmosphere.humidity,2):r.heatindex=n.item.condition.temp,"3200"==n.item.condition.code?(r.thumbnail=a,r.image=a):(r.thumbnail="https://s.yimg.com/zz/combo?a/i/us/nws/weather/gr/"+n.item.condition.code+"ds.png",r.image="https://s.yimg.com/zz/combo?a/i/us/nws/weather/gr/"+n.item.condition.code+"d.png"),r.alt={temp:e(i.unit,n.item.condition.temp),high:e(i.unit,n.item.forecast[0].high),low:e(i.unit,n.item.forecast[0].low)},"f"===i.unit?r.alt.unit="c":r.alt.unit="f",r.forecast=[];for(var m=0;m<n.item.forecast.length;m++)o=n.item.forecast[m],o.alt={high:e(i.unit,n.item.forecast[m].high),low:e(i.unit,n.item.forecast[m].low)},"3200"==n.item.forecast[m].code?(o.thumbnail=a,o.image=a):(o.thumbnail="https://s.yimg.com/zz/combo?a/i/us/nws/weather/gr/"+n.item.forecast[m].code+"ds.png",o.image="https://s.yimg.com/zz/combo?a/i/us/nws/weather/gr/"+n.item.forecast[m].code+"d.png"),r.forecast.push(o);i.success(r)}else i.error("There was a problem retrieving the latest weather information.")}),this}})}(jQuery);function loadWeather(location, woeid) {  $.simpleWeather({    location: location,    woeid: woeid,    unit: 'f',    success: function(weather) {      ASLEvent('SetTempF',weather.temp);ASLEvent('SetCityFromWeather',weather.city);ASLEvent('SetWeatherCode',weather.code);ASLEvent('SetTempCelsius',weather.alt.temp);setTimeout(function(){html = '<h2><i class="icon-'+weather.code+'"></i> '+weather.temp+'&deg;'+weather.units.temp+'</h2>';      html += '<ul><li>'+weather.city+', '+weather.region+'</li>';      html += '<li class="currently">'+weather.currently+'</li>';      html += '<li>'+weather.alt.temp+'&deg;C</li></ul>';              $('#weather').html(html); },500);   },    error: function(error) {      alert('error with weather');      $("#weather").html('<p>'+error+'</p>');  }  });};]]></description>
    <attr name="implementation_notes"><![CDATA[simpleWeather.js<br/><br/>MIT license<br/><br/>----------------------------------------------------------------------------------<br/><br/>Copyright (c) 2016 James Fleeting, http://jamesfleeting.com/

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
            ]]></attr>
  </object>
  <function name="SetMonth" parameters="month">
    calendar.month = month
  </function>
  <function name="HolidayMessage" parameters="holiday" type="string">
    return (StringDictionaryItem(calendar.holidays,holiday))
  </function>
  <function name="SetHoliday" parameters="holiday">
    calendar.isHoliday = true
    calendar.holiday = holiday
  </function>
  <function name="SetDay" parameters="day">
    calendar.day = day
  </function>
  <function name="SetTempF" parameters="temp">
    calendar.tempF = temp
  </function>
  <function name="SetWeatherCode" parameters="weatherCode">
    calendar.weatherCode = weatherCode
  </function>
  <function name="SetCityFromWeather" parameters="city">
    calendar.weatherCity = city
  </function>
  <function name="SetTempCelsius" parameters="tempCelsius">
    calendar.tempC = tempCelsius
  </function>
  <function name="WeatherStatus" parameters="code" type="string">
    status = StringDictionaryItem(calendar.weatherCodeDict,code)
    return (status)
  </function>
  <function name="SetCityManually" parameters="city">
    calendar.playerCity = city
  </function>
  <function name="SetYear" parameters="year">
    calendar.year = year
  </function>
</asl>


NOTES

  • The values of calendar.weatherCodeDict need to be doctored up a little so the messages make sense in any given instance. (It's clear here, but, if I try different cities, it doesn't always read correctly.

  • I need to make it only accept a city name, I think. (I.e., I put Memphis. I don't know what happens if I put Memphis, TN.) Never mind. This works fine. You can put "Memphis, TN", or just "Memphis", or even "Manchester, U.K.".

  • There are surely are other things I'm overlooking, too.


Hey, Anonynn...

Anonynn... Anonynn...

That's fun to say!!!


I think I got side-tracked. (Does "sidetracked" need to be hyphenated? Hrmm...)

What are we supposed to be doing, again?


So basically, I need something that takes the IRL day/month of the player when the game is started, and then it sets that date to an in-game calendar. The in-game calendar will hold the game's holidays (because time moves faster in my game than in real life). But yes, when the day/night cycle goes from night to morning it will advance the calendar day ^_^

If setting up the real-life day to the in-game calendar is too difficult, I can just randomize the day the player starts in the in-game calendar and that should be great.

Make sense xD?

EDIT
Actually, I'm fine with just an in-game calendar and randomizing the player's start date. No need to complicate it.

Anonynn.


>So basically, I need something that takes the IRL day/month of the player when the game is started, and then it sets that date to an in-game calendar. The in-game calendar will hold the game's holidays (because time moves faster in my game than in real life).

Done.

(Merry Belated Christmas!)

http://textadventures.co.uk/forum/quest/topic/1squikhpmeccs2uno8ydyg/date-time-and-weather-work-in-progress#64f7686c-287c-47d6-b60c-db578d7c55a2


>Actually, I'm fine with just an in-game calendar and randomizing the player's start date. No need to complicate it.

That's what my good, old Pappy used to say:

"K.I.S.S."

...and now I'll tell you just like I used to have to tell him:

"Too late! Sorry!"


Haha, thanks! I'll check it out, although holy crap that looks super complicated. I already have a weather/day-night library too that I created, so it'll take some looking through this to customize it for my game! :D Wow, you work fast K.V! I wish I had your coding knowledge! I'm still such a newbie.

How have things been anyway?

Also, do you want to see what I've got to see if things match up?

This is what I have so far.

<object name="calendar">
        <inherit name="editor_object" />
        <holidays type="stringdictionary">
          <item>
            <key>loversGala</key>
            <value>Lover's Gala!</value>
          </item>
          <item>
            <key>feastofFertility</key>
            <value>Feast of Fertility!</value>
          </item>
          <item>
            <key>hallowsShroud</key>
            <value>Hallow's Shroud!</value>
          </item>
          <item>
            <key>winterRepast</key>
            <value>Winter Repast!</value>
          </item>
        </holidays>
        <isHoliday type="boolean">false</isHoliday>
        <holiday type="string"></holiday>
        <alias>Calendar</alias>
        <inventoryverbs type="stringlist">
          <value>Look at</value>
        </inventoryverbs>
        <alt type="stringlist">
          <value>calendar</value>
          <value>cal</value>
          <value>date</value>
          <value>planner</value>
          <value>agenda</value>
        </alt>
        <listalias><![CDATA[<font color="dedede">Calendar</font color>]]></listalias>
        <displayverbs type="stringlist">
          <value>Look at</value>
        </displayverbs>
        <dropmsg>You probably shouldn't let this go. </dropmsg>
        <take />
        <takemsg>You take the calendar in hand. </takemsg>
        <drop type="script"><![CDATA[
          msg ("<br/>You probably shouldn't let this go because it'll help keep track of your calendar days in-game, but if you insist on going without it, you can drop it. Do anything else to Cancel. ")
          menulist = Split("Drop It;Hold Onto It", ";")
          ShowMenu ("", menulist, true) {
            if (result = "Drop It") {
              msg ("<br/>You decide to drop your calendar. Don't lose track of time! ")
              MoveObjectHere (this)
            }
            else if (result = "Hold Onto It") {
              msg ("<br/>You decide to hang onto your calendar for the time being. ")
            }
          }
        ]]></drop>
        <look type="script"><![CDATA[
          game.text_processor_this = this
          msg ("<br/><font size=\"2\"><b>[ <font color=\"dedede\">Holiday</font color> ]</b></font color><br/><font color=\"f6d822\">January</font color><br/><font color=\"dedede\">February 1-20</font color>: Lover's Gala.<br/><font color=\"f6d822\">March</font color><br/><font color=\"dedede\">April 1-15</font color>: Feast of Fertility.<br/><font color=\"f6d822\">May</font color><br/><font color=\"dedede\">June</font color><br/><font color=\"f6d822\">July</font color><br/><font color=\"dedede\">August</font color><br/><font color=\"f6d822\">September</font color><br/><font color=\"dedede\">October 15-31</font color>: Hallow's Shroud.<br/><font color=\"f6d822\">November</font color><br/><font color=\"dedede\">December 15-30</font color>: Winter Repast.</font size><br/><br/><i>Volume</i>: {this.volume}")
        ]]></look>
      </object>
    <function name="SetHoliday" parameters="holiday">
	   switch (holiday) {
      case ("hallowsShroud") {
        game.hs = true
      }
      case ("loversGala") {
        game.lg = true
      }
      case ("feastofFertility") {
        game.fof = true
      }
	   case ("winterRepast") {
        game.wr = true
      }
    }
   </function>
   <function name="SetMonth"  parameters="month">
  game.month = month
</function>
   <function name="SetDay" parameters="day">
    calendar.day = day
  </function>

Do I need to add anything else? xD

Also, I might need a break down of how to display the text processor weather conditions depending on the month. Like...

{if game.month>=11:It's snowing!}
{if game.month<=10:It's raining!}

^ Like that?

Thanks for your patience and help!

Anonynn.


Halpameeee! :P


I missed your last post somehow!

..but I've been well, and I hope you have been well, as well!


So do you want to bring in the actual date in the start script with JS?

// Setup a variable called 'today', which returns today's date.
var today = new Date();

//Setup a variable called 'dd' and set to the day from the date.
var dd = today.getDate();

//Setup a variable called 'mm' and set to the month from the date.
var mm = today.getMonth()+1;

This sounds like all you really need, as long as the actual year, time and weather conditions are insignificant.

I'd set up one function in Quest called SetupDate.

  <function name="SetupDate" parameters="param">
    params = Split(param,";")
    calendar.day = params[0]
    calendar.day = ToInt(calendar.day)
    calendar.month = params[1]
    calendar.month = ToInt(calendar.month)
  </function>

So, your JS function in your start script would be:

JS.eval("setupDate = function(){var today = new Date();var dd = today.getDate();var mm = today.getMonth()+1;var dateParam = dd + ';' + mm;ASLEvent('SetupDate',dateParam);};setupDate();")

That will run when set up, then you could call it whenever by doing:

JS.setupDate()

The weather:

Your way should work if you change the month and day to integers first.

calendar.month = ToInt(calendar.month)
calendar.day = ToInt(calendar.day)

I added that to my SetupDate script recently.


PS

I removed all of the ASLEvents except for the one that sets the month and day.

So, to check for a holiday:

if (calendar.month = 2){
  if ((calendar.day >1) and calendar.day<20){
    calendar.lg = true
  }
}

Then:

if(HasAttribute(calendar,"lg")){
  if(calendar.lg){
    msg("It's the Lover's Gala REMIX!!!")
  }
}

PPS

If you knew for sure that calendar.lg existed as a Boolean from the start of the game, you could lose the if(HasAttribute(calendar,"lg")){ bit (along with the last }), making that script:

if(calendar.lg){
  message = StringDictionaryItem(calendar.holidays,"loversGala")
  msg(message)
}

Here's a new SetHoliday (no parameters, no return value):

<function name="SetHoliday">![CDATA[
switch (calendar.month) {
  case (1) {
  }
  case (2) {
    if (calendar.day<=20) {
      calendar.lg = true
    }
  }
  case (3) {
  }
  case (4) {
    if (calendar.day<=15) {
      calendar.fof = true
    }
  }
  case (5) {
  }
  case (6) {
  }
  case (7) {
  }
  case (8) {
  }
  case (9) {
  }
  case (10) {
    if ((calendar.day>=15) and calendar.day <=30) {
      calendar.hs = true
    }
  }
  case (11) {
  }
  case (12) {
    if ((calendar.day>=15)and calendar.day <=30) {
      calendar.wr = true
    }
  }
}
]]></function>

Sorry, I had just come down with the flu for my first time on the 30th, and I have been scatter-brained.

I edited that last function to include <![CDATA[.


Log in to post a reply.

Support

Forums