Get Today's Real Date? #1621
-
|
I see example libaries, and I even have a working Date/Time system, but I can't seem to to find working JS.Eval or already included methods of retriving, and using the current date. For example, during certain holidays having nice messages or descriptions or having an happy holidays message. Thank you in advance. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
|
The "easiest" way to use the actual current time and date from Quest code is this function (which returns an integer): At this time (while typing this), that returns https://docs.textadventures.co.uk/quest/functions/currentDateUTC.html |
Beta Was this translation helpful? Give feedback.
-
|
Two options. So you could do something like: Which will then (after a small delay) call a Quest function which could look like this: (Note: I added +1 to the month, because that's more human-readable. Because April = 4 is what most people would expect. Numbering days doesn't have such a convenient single way of numbering, so I left While this code is somewhat more human readable, it will be slower than using a native Quest function; the Alternatively, if the delay is a problem for you Off the top of my head, it would look something like this: I think that's right. But I already posted this wrong and then edited it. This stuff is one of the easiest places to make careless errors in all of programming; which is why just about every programmer will use a pre-written function for it if there is one. Also, the function name suggests that this is UTC - so it will tell you what the date would be in the UK if we didn't have daylight saving, not in the player's timezone. The Javascript version uses the clock on the player's computer, so it could be wrong (and potentially allows the player to cheat, if you hide big rewards behind it) - but you know that for most people, it will match the time they want to use. In most cases, I recommend the JS. |
Beta Was this translation helpful? Give feedback.
Two options.
If you use Javascript, you can use the internal Date functions to get different parts of the day; but you'd need to use a function to pass the data back. So there will be some delay.
So you could do something like:
Which will then (after a small delay) call a Quest function which could look like this: