1

I'm trying to run the following code as a sahi script:

_include("initialScript.sah");
_include("secondScript.sah");

function currentTime(){
    var $current = new Date();
    var $hours = $current.getHours();
    var $minutes = $current.getMinutes();

    if ($minutes < 10){
        $minutes = "0" + minutes;
    }

    if($hours > 11){
        _log("It is " + $hours + ":" + $minutes + " PM");
    } 
    else {
        _log("It is " + $hours + ":" + $minutes + " AM");
    }

    if($hours >= 8 || $hours =< 20) {
        _include("aScript.sah");
        _include("anotherScript.sah");
        ...
    }
    else {
        //do nothing and continue below
    } 
}

_include("yetMoreScripts.sah");
...

Simply put, I have a block of various scripts, followed by a check of the current time. If it isn't between 8am and 8pm, the included block of scripts is skipped and the others below are executed. The _logs tell me that getting the time appears to work as intended. Yet whenever I attempt to run the script as is, I get an immediate failure and completely unrelated Syntax Errors (such as on an _include way further down that is not faulty at all). Taking the _includes out of the if Statement seems to make the errors stop. For all I know this should work but just doesn't. Does anybody have experience with something similar and could give me a hint as to where I made a mistake?

hiyosilver
  • 27
  • 5

1 Answers1

1

as far as I can tell, this should work. A simple test:

test1.sah:

_log("ok");

test2.sah:

if (true) {
  _include("test1.sah");
}

When I run this from the Sahi Controller, I get an "ok" logged. Maybe recreate this test and check if you get the same results. Maybe it's the ";" missing after your includes? Are you passing dynamic values to include? like _include($path)?

globalworming
  • 757
  • 1
  • 5
  • 33
  • I put the function in my functions document instead of the main script and simply made it output a boolean value based on the current time. In the main script I then called that function, checking the boolean in another if-statement and executing or skipping the relevant _includes. It appears to be working now. While your answer wasn't strictly 'right', you reminded me to check my Syntax again, which allowed me to help myself. Therefore I will mark this as the correct answer. Thank you. :) Edit: there were no missing semicolons. I just didn't copy them for some reason. – hiyosilver Mar 28 '14 at 14:22