How does isLaterOrEqualThan work and how can I use it in modding

Hello there, another question. What the title says. What does this do? I found this in the game’s code.

a.isLaterOrEqualThan = function(a, c, b) {
        var e = this.getCurrentDate();
        return e.year > a || e.year === a && e.month > c || e.year === a && e.month === c && e.week >= b
    };

a. is

var a = Company.prototype;

I don’t know the rest, so I can’t know what a, c, b are. Maybe it’s year, month, week? Please answer, and if it’s possible to be put into an api mod, many thanks.

It essentially checks if some is less or equal to something, kinda self explanatory

Is it used with dates? Can I add this to a research in the CanResearch so if a time passes, It just pops-up and can be researched?

It can be used with more then dates i believe

1 Like

How can I put it into a mod with the api? Paste the code?

noitdoesnot

@tmch

Key words here

Well? Any help of making use of it in mods and what it does?

returns a boolean whether it is over year,month,week

1 Like

a.isLaterOrEqualThan = function(a, c, b) {
        var e = this.getCurrentDate();
       
return e.year > a || e.year === a && e.month > c ||
e.year === a && e.month === c && e.week >= b
    };

so, a = year, c = month and b = week?

3 Likes

I understand, you call the function with with a date and it returns true if is later or equal to the current week. For example:

var z = isLaterOrEqualThan(20,5,2)

z is true if the current date is later or equal than the year 20 month 5 week 2

2 Likes

you forgot the semicolon :angry:

1 Like

@tmch pfft, nevermind semicolons

@Mabb thanks, I suppose I can use it in normal researches, right?

1 Like

@tmch in C t he program dont work without semicolons but in javscript it sems you dont need it
@FireChaos i don t know how the research system works but probably you can add a condition that only add the research when it s true. Look the other mods code or the game code how they did. Now i can 't have acces to my computer i can t help you more.

I dont think if statements really work, I get errors all the time, but I’ll try.

Semicolon-less is ok 99 times out of 100. The 100th time is this:

return
{
    some: 'object'
}

Which returns undefined.

2 Likes

So, what do I need to do here?

isLaterOrEqualThan(15, 5, 2) will tell you whether the current date is on or after the second week of the fifth month of the fifteenth year. Possibly need to -1 each of them, can’t remember if dates in GDT are zero based atm.

You might use this a trigger for one of your events. If you wanted to have a chance for the player to win a competition from year 20, you might have a trigger function like so:

trigger: function (company) {
    return company.isLaterOrEqualThan(20, 1, 1) && Math.random() > 0.8;
}

Because it is on the Company prototype, you need an instance of company to actually call the function. (If you tried to COmpany.prototype.isLaterOrEqualThan it would complain about missing getCurrentDate() )

2 Likes

Thanks for that, but can it be used with researches? I hope so. So we can trigger a research much like Achievements or Save to cloud which are able to research with that same thing.

You’re given the current company instance as a parameter to canResearch, so yes, you can use it there.

2 Likes