Holiday events

EvilDennis

Warper
Member
Joined
Dec 4, 2017
Messages
2
Reaction score
1
First Language
German
Primarily Uses
Other
Hey,
I want to make events in my game, which just appear for example at Halloween or Christmas.
So if you play the game at the 24th of December, a special event will be triggered.
Is there a possibility to use the date of the OS in the game?
 

Dreadshadow

Lv 38 Tech Magician
Moderator
Joined
Mar 2, 2014
Messages
3,852
Reaction score
2,511
First Language
Greek
Primarily Uses
RMMV
Most probably you should be fine by setting up a variable with the system's month and another one with system's day. From that point it's as simple as using some Conditional Branches to check if an event shall occur.

So you are looking for a js command to set current day and current month as values on two variables.

I know that the command to set a value into a variable should be something like this:

$gameVariables.setValue(var, value);

where
var is the id number of the variable
and
value its value to be set.

So we can create an object named dt that it will be a date object.

var dt = new Date();



This dt has attributes and methods to grab those attributes.
We will make two variables, m and d and grab the attributes Month and Day
by using those methods:

var m = dt.getMonth();
var d = dt.getDay();



Use a Script Event Command (third tab Advanced, on Event Commands) and paste this in it:

var dt = new Date();
var m = dt.getMonth();
var d = dt.getDay();
$gameVariables.setValue(1, m);
$gameVariables.setValue(2, d);



You are all set. Months are on Variable 1 and Days on Variabe 2.
If you want to set them to different numbers go on and change that 1 and that 2.

Now if you want you can use an Event Command Show Message to see if it works:
It must contain this:

\V[1] \V[2]

It will show the contents of the variable 1 along with the contents of variable 2.

You can now use Variables 1 and 2 to Conditional Branches to check for special events.
P.S. Don't forget to name the variables. Something like SysMonth, SysDay.
 
Last edited:

EvilDennis

Warper
Member
Joined
Dec 4, 2017
Messages
2
Reaction score
1
First Language
German
Primarily Uses
Other
I don't know why, but my game tells me the wrong date.
By using this, it tells 4th October and not today (8th November).
 

Dreadshadow

Lv 38 Tech Magician
Moderator
Joined
Mar 2, 2014
Messages
3,852
Reaction score
2,511
First Language
Greek
Primarily Uses
RMMV
You are right. I am not sure what is going on either, it might has to do with the object initialization.

var dt = new Date();

I will research it further.
For now you can do this:

var dt = new Date();
var m = dt.getMonth();
m = m+1;
var d = dt.getDay();
d = d+4;
$gameVariables.setValue(1, m);
$gameVariables.setValue(2, d);



That should fix it. Give me some time to research why it behaves like that.
I think I shall open a new thread on that.
It's either a bug or a... feature.
Nonetheless, try out the code above, it will fix your issue.

Just for the record here is a script that includes the year.
Oh! By the way, the year needs to add 1900 to show the proper number, as shown below:


var dt = new Date();
m = dt.getMonth();
d = dt.getDay();
y = dt.getYear();
m = m+1;
d = d+4;
y = y+1900;
$gameVariables.setValue(1, m);
$gameVariables.setValue(2, d);
$gameVariables.setValue(3, y);
 
Last edited:

Aloe Guvner

Walrus
Veteran
Joined
Sep 28, 2017
Messages
1,627
Reaction score
1,061
First Language
English
Primarily Uses
RMMV
I don't know why, but my game tells me the wrong date.
By using this, it tells 4th October and not today (8th November).
The month given by the getMonth() function is correct, it's just zero-indexed (like most programming things). So the month given as 10 is actually November.
The month 4 is May, the month 7 is August, etc.

@Dreadshadow the getDay function gets the day of the week (i.e. Thursday), so that is not the correct approach to getting the date :)

You would be better off using Date.getDate()

For Javascript questions, always try the MDN site :)

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getMonth
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getDay
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getDate
 
Last edited:

Dreadshadow

Lv 38 Tech Magician
Moderator
Joined
Mar 2, 2014
Messages
3,852
Reaction score
2,511
First Language
Greek
Primarily Uses
RMMV
Oh! Makes sense now. I mean ok the zero indexed case was something I imagined, but the day (0 - 6) didn't passed my mind, thus the approach is wrong.
So it means that
d = dt.getDay();
should be
d = dt.getDate();
and it should work correct, right?

Edit:
P.S. Your links were great! Thanks for sharing this website. I should had imagined that Firefox team would have documentation (since JS started from Netscape)

So let me check if the following works...yes it does!
@EvilDennis replace the previous code with this one below:


var dt = new Date();
m = dt.getMonth();
d = dt.getDate();
y = dt.getFullYear();
m+=1;
$gameVariables.setValue(1, m);
$gameVariables.setValue(2, d);
$gameVariables.setValue(3, y);

Or you can even copy paste THAT code below, because it does the same job with less variables on the script:

var dt = new Date();
$gameVariables.setValue(1, dt.getMonth()+1);
$gameVariables.setValue(2, dt.getDate());
$gameVariables.setValue(3, dt.getFullYear());
 
Last edited:

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Profile Posts

Please support my Lego Ideas Untitled Goose Game set, thanks in advance :) https://ideas.lego.com/projects/2bcb743a-1071-4f44-89f4-97ad6ec27b5d
Here we are....REMIND is out and what am I doing?
Still Playing Kingdom Hearts 3.....
Escort quest is one of the worst quest ever because the AI tend to be suck and suicidal.
New update/finish/fix/upload TODO list:
AddCancelCommand, AutoshadowEx, BgImageScreenShot, BindEvents, ChangeEventGraphic, DroppingGame, EscapeCodesEx, EventTriggersEx, FortuneCookie, GameoverEx, InputEx, InsertValues, LastCalledEvent, LevelUpEx, MapData, MemoryGame, MessageSetSwitch, MogCharPosesEx, MonstersCaught, MovementEx, ...
... continued below...

Forum statistics

Threads
93,582
Messages
913,682
Members
123,119
Latest member
Zhivago
Top