Time conditional for choosing content

Any freelancer willing to do this job for me?

Here's a starting point for you:

Thank You Daniel. I will take a close look. I really appreciate your advice.

This is my script on scene load:

var month = moment().format("M");
var day = moment().date();
var year = moment().format("YYYY");

if (day == 26 && month == 6 && year == 2019 ) hypeDocument.showSceneNamed('IGUAZU');
 
else hypeDocument.showNextScene();

This is my set up on scene unload:
Action: jump to a scene
Scene: Next

Can you find the error?

Seems “else” line works, but “If” line doesn’t. It keeps loading all time the scenes lasts, and it doesn’t jump to next scene.

Console says: Error in undefined: RangeError: Maximum call stack size exceeded - HYPE-648.full.min.js:140

Take a look at the Javascript School page for “Dates”, it may give you another starting point…

https://www.w3schools.com/jsref/jsref_getfullyear.asp

1 Like

Please @Daniel, help me with this

Code with no dependency on moments.js using @gasspence suggestion:

var d = new Date();
var year = d.getFullYear();
var month = d.getMonth() + 1;
var day = d.getDate();

if (day == 27 && month == 6 && year == 2019 ) {
    hypeDocument.showSceneNamed('IGUAZU');
} else {
    hypeDocument.showNextScene();
}

dateSelector.hype.zip (40,1 KB)

4 Likes

Thank you Max, We are getting steps forward.

This code works fine, Max:

var d = new Date();
var year = d.getFullYear();
var month = d.getMonth() + 1;
var day = d.getDate();

if 	(day == 27 && month == 06 && year == 2019 ) {hypeDocument.showSceneNamed ('IGUAZU');}

else {hypeDocument.showSceneNamed('NO_EVENTO')}

But when I try to use multiple conditions, I mixed up:

var d = new Date();
var year = d.getFullYear();
var month = d.getMonth() + 1;
var day = d.getDate();

if 	(day == 27 && month == 06 && year == 2019 ) {hypeDocument.showSceneNamed ('IGUAZU');}

if 	(day == 28 && month == 06 && year == 2019 ) {hypeDocument.showSceneNamed ('CABARET');}

else {hypeDocument.showSceneNamed('NO_EVENTO');}

I have tried changing syntax many times. No solution.

Any ideas, @MaxZieb @Daniel?

This is basic JS knowledge so this is in no way directly Hype related as it boils down to if/else if/else. Please read up on the following. :

If you prefer you might also try a switch statement:

Also make sure to check out these free tutorials:

Hope this helps!

2 Likes

Thank you Max. I went back to school and find answers to my problems. :smiley:

Guys. I send you my working script:

var d = new Date();
var year = d.getFullYear();
var month = d.getMonth() + 1;
var day = d.getDate();


if (day == 27 && month == 6 && year == 2019 ) {hypeDocument.showSceneNamed('MALABARISTA');}
else if (day == 29 && month == 06 && year == 2019 ) {hypeDocument.showSceneNamed('IGUAZU');}
else  {hypeDocument.showSceneNamed ('NO_EVENTO');}
1 Like

How can substitute last code line,

else {hypeDocument.showSceneNamed (‘NO_EVENTO’);}

by a costume embedded function to be instantly execute on that line?
I have searched a lot. Can you give me a hint?

It has to be something like this

else {myhypedocument.functions().myFunction();}

Have another look at this link (already posted by @Daniel above) which shows the use of the hypeDocument.functions() in a situation similar to yours.

Also attached is a basic example showing the use of hypeDocument.functions()
Hype_Functions_Call_JHSv1.hype.zip (12.4 KB)

Yes, in theory everything is clear to me on this point, but on this case I can’t make it work. Here my script:

var d = new Date();
var year = d.getFullYear();
var month = d.getMonth() + 1;
var day = d.getDate() + 6;
var opt = 'PLUSTHREE'

// JULIO
if (day == 13 && month == 7 && year == 2019 ) {hypeDocument.showSceneNamed('DRAGONFLY'); hypeDocument.startTimelineNamed(opt);}
else if (day == 15 && month == 7 && year == 2019 ) {hypeDocument.showSceneNamed('NIETO'); hypeDocument.startTimelineNamed(opt);}
else {hypeDocument.functions().Selector_PlusTwo(hypeDocument, element, event);}

The function ‘Selector_PlusTwo’ script is almost the same script as the above, except for variable ‘opt’ and ‘day’

Do I have to define anything on (hypeDocument, element, event)?
What’s missing?

The issue you seem to be having is you do not understand the syntax of javascript.

Your if condition closures are not correct.

for instance you have

// JULIO
else if (day == 13 && month == 7 && year == 2019 )

This makes no sense. else if from what…?
Also you have missed the closure brackets {}.

Two suggestions.

When you type out an if condition. type it like this first

if (){
}

then fill it in by putting the condition between the first brackets ()

if (day == 13 && month == 7 && year == 2019){
}

Then the what to do if the condion is met between the curly {} brackets. .

  if (day == 13 && month == 7 && year == 2019){
    
  hypeDocument.showSceneNamed('DRAGONFLY'); 
 hypeDocument.startTimelineNamed(opt)
}

If you are doing an else if after an if condition block then do the same

  if (){
    } else if () {
}

and an else completion is similar but without a condition.

 if (){
    } else if () {
} else {


}

resulting code.

var d = new Date();
    var year = d.getFullYear();
    var month = d.getMonth() + 1;
    var day = d.getDate() + 6;
    var opt = 'PLUSTHREE'

    // JULIO
     if (day == 13 && month == 7 && year == 2019 ) 
     {
     
      hypeDocument.showSceneNamed('DRAGONFLY'); 
     hypeDocument.startTimelineNamed(opt)
     
     } else if (day == 15 && month == 7 && year == 2019 ){
     
     hypeDocument.showSceneNamed('NIETO');
     hypeDocument.startTimelineNamed(opt)
     
     } else {
     
     hypeDocument.functions().Selector_PlusTwo(hypeDocument, element, event)
     
     }

suggestion two
I think you need to look at the basics of javascript syntax which will help you.
for example.

https://www.w3schools.com/js/js_if_else.asp

2 Likes

Thank you guys for the help.

Read my post again, I hit submit before I had finished writing it…

Everything working fine. At the end, the mistake was just a extra semicolon on the last line, that was not required. Sorry to bother for such a thing.

Here my contribution. In relation to the following code, gently introduced by @MaxZieb, We were using on this thread:

var d = new Date();
var year = d.getFullYear();
var month = d.getMonth() + 1;
var day = d.getDate() + 6;

I have been trying the code many times for any casuistic possible. The conclusion is variables definitions We did, do not work for all the cases. If today were July 31st, you can’t add even a day more to see what happens on August 1st. That meas that the code can not be use for the purpose of getting dates in advance or regression.

The code I am using at the moment is:

var day = new Date();
var thirDay = new Date(day);
thirDay.setDate(day.getDate()+365);
var year = thirDay.getFullYear();
var month = thirDay.getMonth() + 1;
var day = thirDay.getDate();

With this code you can add any number to get any date, for years in advance or regression.

1 Like

Me initially replying was to the premise of checking against today (is today this or that day, month, year etc.) with some fixed numbers. Having a date in the future doesn’t make sense in that premise.

Glad you solved it for your extended purpose… though.

You are right Max. Thank you.