The best place to *find* answers to programming/development questions, imo, however it's the *worst* place to *ask* questions (if your first question/comment doesn't get any up-rating/response, then u can't ask anymore questions--ridiculously unrealistic), but again, a great reference for *finding* answers.

My Music (Nickleus)

20130428

sahi - run block of code only if script called from another script

here's how you conditionally run a block of code in a sahi script (sahi_script2.sah), but only if that script first gets called by another sahi script (sahi_script1.sah).

#############sahi_script1.sah##############

//some sahi code ...

var $write_wd_to_file = true;

_include("sahi_script2.sah");    // RUN sahi_script2.sah

//some sahi code ...

########################################


#############sahi_script2.sah##############

//some sahi code ...

/*
IF YOU CALL sahi_script2.sah DIRECTLY, THEN THIS WONT GET RUN
*/
// $write_wd_to_file gets set in sahi_script1.sah
if($write_wd_to_file) {
    var $weeklyDepartureId = $routeplanName + "_WD";
    _writeToFile($weeklyDepartureId, "weekly_departure_id.txt", true);
    _wait(2000);
}

//some sahi code ...

########################################


sahi_script1.sah runs some code, then runs sahi_script2.sah, which writes a string to a file

if sahi_script2.sah gets runs directly, then that block of code won't get run and nothing will get written to a file.

No comments:

Post a Comment