[SOLVED] Getting current date through code

Hi I have an Online Game and would like to add events to it I don’t know how to get the date.
is there any way of doing this or am i out of luck?

Hi @WilliamBoersma31,

Check the following article on the native Date object, you can easily use it to get access to the current date in the client.

Ideally you would calculate it in the server and pass it to the client, for a more secure and authoriative experience.

2 Likes

What game is it that your working on

I’m working on multiple games but in this case I just want to change a couple textures when it’s a specific date example: Make the floor bloody on Halloween or Make the characters red and green on Christmas ext ext

Thanks, I Got The First One Of The Games Working And Made An System For Future Games. Here Is The Code For Anyone Interested.

var DateCheck = pc.createScript('dateCheck');
DateCheck.attributes.add('Date', {type:'string', title: 'Test Date To Check'});
DateCheck.attributes.add('Test', {type:'rgba', title: 'Test Col'});

DateCheck.prototype.initialize = function() {

};

DateCheck.prototype.update = function(dt) {
        var mat = this.entity.model.material;
  var date = new Date();
//Checking If The date matches the test date
// You can hard code any date you want
    if (date.toString().includes(this.Date) && this.Date != "") {
 
            mat.diffuse = this.Test;
            mat.update();
            
        
    }
};
1 Like