MV Read system time in-game

Hiya. Yep, another post. All I want to do is give my game the ability to read the computer's time. I know there's already an existing plugin for that, but it costs money, and I don't have the money to purchase it. I'm just some random teenager that makes YouTube content for no reason, and chats with Discord friends every day, occasionally daydreaming about a time where I'll have money to spend.

Could someone point me to an alternative? I kinda want a plugin that can do what the paid plugin can do so I can make special events for "if the date is so-and-so". That's all. Normally I would say "that's a lot of money for something that can only do this and that", but I understand coding stuff like this is difficult, and sometimes you've just got to find a way to make that profit (if only I had a "way". I'm monetized on YouTube but I need my mom to fill out "tax information" before I can actually get paid).

Also, before you say "just let the player enter the time and date", that can easily be exploited. I don't want to allow the player to trigger a "happy birthday to this character" event whenever they want to, I want them to be able to see those events ONLY on the character's birthday. Stuff like that.

Last thing I want to say is, I can understand if your reply is going to be "making a plugin that can do what the paid plugin can do completely defeats the purpose of the paid plugin", I just don't want to scrape/pirate a plugin just so I can do what I want for my game. That's why I asked for an alternative. Plus; I'm sure some people have made plugins for things that are already covered by another plugin, rookie mistake, right? Didn't look around before making the plugin... eh...…? What I'm saying is, I'm just wondering if someone else has made a similar plugin that doesn't cost anything. It's like Microsoft Office and LibreOffice. If you don't have the money for Microsoft Office, you could use LibreOffice for free. Except... paid plugins vs free plugins isn't the same as Microsoft Office and LibreOffice, is it... I'm bad at comparisons, okay?

That's the end of this gargantuan post. So much for "this one's REALLY short and sweet", I cut that part out as the post got bigger. Anyway... opinions? Help? Anything?
The JavaScript code:
Code:
Date()
will return a string that represents the current time and date as held by the system the program that calls the code is operating on.

1626583479818.png

More information on this native function can be found here.

You can utilize this information in scripts by implementing the 'String.prototype.includes()'
function, which you can learn more about here.

Here in an example of some code that makes use of 'Date()' and 'Date().includes()'

Spoiler: Before midnight
1626584601100.png

Spoiler: After Midnight
1626584611726.png

I ran the same code before and after midnight, notice how the message logged to the console changed after the weekday changed at midnight.

Utilizing these functions, you wouldn't need a plugin.
That actually helps a lot!!! Any idea how to get this stuff into variables?
Edit: I forgot about some parts, I'll reread.
Edit 2: OMG I GOT IT!!!! THIS IS SO EXCITING!!!
You can do something like,

JavaScript:
if (Date().includes('Sat')) {$gameVariables.setValue(1, 6)}

Or, you can use a switch statement to handle it all at once,
Spoiler: Switch Statement
JavaScript:
var date = new Date().getDay();
switch (date) {
  case 0:
    $gameVariables.setValue(1, 1);
    break;
  case 1:
    $gameVariables.setValue(1, 2);
    break;
  case 2:
    $gameVariables.setValue(1, 3);
    break;
  case 3:
    $gameVariables.setValue(1, 4);
    break;
  case 4:
    $gameVariables.setValue(1, 5);
    break;
  case 5:
    $gameVariables.setValue(1, 6);
    break;
  case 6:
    $gameVariables.setValue(1, 7);
    break;
}

You can read about how switch statements work here.

In the example, I used new Date().getDay() to return a number from 0 to 6, zero being Sunday and 6 being Saturday. Then I saved that value to Variable 1. I started with 1 because all the game variables start at zero by default, so trying to use zero for Sunday could cause problems.
Call the function inside an Rpg Maker variable via the Script field or use reuse in other scripts.
RMMV-RealTime-GameVariables.png

JavaScript:
/*:
 * @plugindesc Call the function inside an Rpg Maker variable via the Script field or use reuse in other scripts.
 * @author Nobody
 *
 * @help getRealTime.js
 * Instructions:
 * call getRealTime() on Rpg Maker Control Variable
 *
 * To Year (4 digits): getRealTime("year")
 * To Month: getRealTime("month")
 * To Number day: getRealTime("day")
 * To Week day: getRealTime("week")
 * To Hours: getRealTime("hours")
 * To Minutes: getRealTime("minutes")
 * To Seconds: getRealTime("seconds")
 *
 * On dialog \v[id] return Computer Time
 */
 function getRealTime(d){
    var t = new Date(), rt;
    var week = [
       "Sunday",
       "Monday",
       "Tuesday",
       "Wednesday",
       "Thursday",
       "Friday",
       "Saturday"
    ];
    
    var spliDate = [
        t.getFullYear(),
        t.getMonth() + 1,
        t.getDate(),
        week[t.getDay()],
        t.getHours(),
        t.getMinutes(),
        t.getSeconds()
    ];
    
    (spliDate[1] < 10) ? spliDate[1]="0"+spliDate[1] : '';
    (spliDate[2] < 10) ? spliDate[2]="0"+spliDate[2] : '';
    (spliDate[4] < 10) ? spliDate[4]="0"+spliDate[4] : '';
    (spliDate[5] < 10) ? spliDate[5]="0"+spliDate[5] : '';
    (spliDate[6] < 10) ? spliDate[6]="0"+spliDate[6] : '';   
    
    switch(d){
        case "year":
            rt=spliDate[0];
            break;
        case "month":
            rt=spliDate[1];
            break;
        case "day":
            rt=spliDate[2];
            break;
        case "week":
            rt=spliDate[3];
            break;
          case "hour":
            rt=t.getHours();
            rt=spliDate[4];
            break;
        case "minutes":
            rt=spliDate[5];
            break;
        case "seconds":
            rt=spliDate[6];
            break;
        default:
            rt=spliDate[0]+"/"+spliDate[1]+"/"+spliDate[2]+", "+spliDate[3]+", "+spliDate[4]+":"+spliDate[5]+":"+spliDate[6];
    }
    return rt;
}
Call the function inside an Rpg Maker variable via the Script field or use reuse in other scripts:
Code:
/*:
 * @plugindesc Call the function inside an Rpg Maker variable via the Script field or use reuse in other scripts.
 * @author Nobody
 *
 * @help getRealTime.js
 * Instructions:
 * call getRealTime() on Rpg Maker Control Variable
 *
 * To Year (4 digits): getRealTime("year")
 * To Month: getRealTime("month")
 * To Number day: getRealTime("day")
 * To Week day: getRealTime("week")
 * To Hours: getRealTime("hours")
 * To Minutes: getRealTime("minutes")
 * To Seconds: getRealTime("seconds")
 *
 * On dialog \v[id] return Computer Time
 */
 function getRealTime(d){
    var t = new Date();
    var rt;
    var week = [
       "Sunday",
       "Monday",
       "Tuesday",
       "Wednesday",
       "Thursday",
       "Friday",
       "Saturday"
    ];
  
    var spliDate = [
        t.getFullYear(),
        t.getMonth() + 1,
        t.getDate(),
        week[t.getDay()],
        t.getHours(),
        t.getMinutes(),
        t.getSeconds()
    ];
  
    (spliDate[1] < 10) ? spliDate[1]="0"+spliDate[1] : '';
    (spliDate[2] < 10) ? spliDate[2]="0"+spliDate[2] : '';
    (spliDate[4] < 10) ? spliDate[4]="0"+spliDate[4] : '';
    (spliDate[5] < 10) ? spliDate[5]="0"+spliDate[5] : '';
    (spliDate[6] < 10) ? spliDate[6]="0"+spliDate[6] : '';
  
  
    switch(d){
        case "year":
            rt=spliDate[0];
            break;
        case "month":
            rt=spliDate[1];
            break;
        case "day":
            rt=spliDate[2];
            break;
        case "week":
            rt=spliDate[3];
            break;
          case "hour":
            rt=t.getHours();
            rt=spliDate[4];
            break;
        case "minutes":
            rt=spliDate[5];
            break;
        case "seconds":
            rt=spliDate[6];
            break;
        default:
            rt=spliDate[0]+"/"+spliDate[1]+"/"+spliDate[2]+", "+spliDate[3]+", "+spliDate[4]+":"+spliDate[5]+":"+spliDate[6];
    }
    return rt;
}
Nice! Whatever I would have come up with would not have been as good as this.
@ThreeSixNine Thank you so much for seeing all the plugin details and considering commenting, rarely does anyone have that kind of common sense.


@kanyatanishande If you don't know how to script JS file, let me know.

You don't need to give me credit and you can use it in commercial games, these are basic javascript functions, I'm not a programmer/scripter, I just followed the basics of the existing functions.

Sorry if I had any inconsistencies in the description in the Plug-in, English is not my first language

Edit:
Spoiler: Date/Time Formated - New Plugin (CLICK HERE)
I've written another plugin that lets you return the date and time already formatted, for example if I want it like this:
YYYY/MM/DD - HH:mm will return 2018/07/18 - 18:08

It also has a return day of the week system with support for 5 languages so far, in full (Sunday) or abbreviated (Sun).
It also includes the parameter in the manager that will return a predefined language.

It also has the numerical option, Sunday retunr 0 and Saturday return 6, you can use this number to customize by events.
Also includes the option to ignore the time zone.
So if for me the clock reads 15:10 because my time zone is "-3" the system will return 18:10

I still haven't concluded why I'm going to try to write the instructions in the same 5 languages and I need to test it in some browsers to see if it really will identify the language of the operating system, for example, on Android it didn't work.
I used it in a different way, in 2-3 variables, which read system time as well.
but everyone use their own methode that works best, but I use a methode which is not as the above.

but you can also seperate all days, months, years in seperate variable to check on if you want
only day or weekday is equal to something for special event/request/free stuff etc =)

the possibility is rather endless though 🙂
JavaScript:
Call the function inside an Rpg Maker variable via the Script field or use reuse in other scripts.


[CODE=javascript]/*:
 * @plugindesc Call the function inside an Rpg Maker variable via the Script field or use reuse in other scripts.
 * @author Nobody
 *
 * @help getRealTime.js
 * Instructions:
 * call getRealTime() on Rpg Maker Control Variable
 *
 * To Year (4 digits): getRealTime("year")
 * To Month: getRealTime("month")
 * To Number day: getRealTime("day")
 * To Week day: getRealTime("week")
 * To Hours: getRealTime("hours")
 * To Minutes: getRealTime("minutes")
 * To Seconds: getRealTime("seconds")
 *
 * On dialog \v[id] return Computer Time
 */
 function getRealTime(d){
    var t = new Date(), rt;
    var week = [
       "Sunday",
       "Monday",
       "Tuesday",
       "Wednesday",
       "Thursday",
       "Friday",
       "Saturday"
    ];
  
    var spliDate = [
        t.getFullYear(),
        t.getMonth() + 1,
        t.getDate(),
        week[t.getDay()],
        t.getHours(),
        t.getMinutes(),
        t.getSeconds()
    ];
  
    (spliDate[1] < 10) ? spliDate[1]="0"+spliDate[1] : '';
    (spliDate[2] < 10) ? spliDate[2]="0"+spliDate[2] : '';
    (spliDate[4] < 10) ? spliDate[4]="0"+spliDate[4] : '';
    (spliDate[5] < 10) ? spliDate[5]="0"+spliDate[5] : '';
    (spliDate[6] < 10) ? spliDate[6]="0"+spliDate[6] : ''; 
  
    switch(d){
        case "year":
            rt=spliDate[0];
            break;
        case "month":
            rt=spliDate[1];
            break;
        case "day":
            rt=spliDate[2];
            break;
        case "week":
            rt=spliDate[3];
            break;
          case "hour":
            rt=t.getHours();
            rt=spliDate[4];
            break;
        case "minutes":
            rt=spliDate[5];
            break;
        case "seconds":
            rt=spliDate[6];
            break;
        default:
            rt=spliDate[0]+"/"+spliDate[1]+"/"+spliDate[2]+", "+spliDate[3]+", "+spliDate[4]+":"+spliDate[5]+":"+spliDate[6];
    }
    return rt;
}
[/CODE]

I know this probably counts as necroposting but...is there any way to get this time to read in standard hour format and not military time. Meaning 1:00-12:59 instead of 14:59 and such. I'm trying to have the time read from a wall clock and wall clocks don't really read in military time.
I know this probably counts as necroposting but...
It does 😛

is there any way to get this time to read in standard hour format and not military time. Meaning 1:00-12:59 instead of 14:59 and such.
Just a conditional and bit of math, right?
Control Variables -> yourVariable -> getRealTime("hours")
Conditional Branch -> yourVariable > 12
-Control Variables -> yourVariable - 12
It does 😛


Just a conditional and bit of math, right?
Control Variables -> yourVariable -> getRealTime("hours")
Conditional Branch -> yourVariable > 12
-Control Variables -> yourVariable - 12
Haha I figured as much.

Either way thanks a ton! Yes with a bit of a reach around and storing the second variable to fix the hour format the time is correct! Thanks a bunch!

Original thread: https://forums.rpgmakerweb.com/threads/read-system-time-in-game.138633/