On 2005-08-04 (14:35) alok vaid wrote:

>Thanks for help. I have implemented message callback function. I
>have another question. I think it is more of a javascript question
>rather than JMol. I want to know how can I keep checking a variable
>for a particular value, in my case "script completed", and when find
>it, I move ahead with my program's next line. i have tried using
>Settimeout function in javascript, but its not working.
>

how about something like this (untested; watch the line wraps!):


function checkIsReady( counter, maxcounter, fcn_to_call ) {
   
   if ( counter == maxcounter ) {
      handleError( 'timed out waiting for end of script!' );
      return;
   }
   else if ( getLine() != 'script completed' ) {
      counter++;
      setTimeout( 
         'checkIsReady(' + counter + ',' + 
         maxcounter + ',"' + fcn_to_call + '")', 
         250 );
   }
   else {
      eval( fcn_to_call + '()' );
   }

}


pass this function an initial counter, a maxcounter (when to stop looping), and 
the actual "working" function to call on success. it keeps calling itself, 
every 250 ms, until either it sees 'script completed' or it hits the max number 
of calls (15 sec in this example).  if it sees 'script completed' before timing 
out, it goes on to call the given function.  if not, it goes to an error 
handing routine.

you can, of course, tweak any part of this to fit your needs.


hth,

tim
-- 
Timothy Driscoll
molvisions - see, grasp, learn.
<http://www.molvisions.com/>
usa:north carolina:raleigh

"Mathematics is the language with which God has written the universe." - 
Galileo Galilei


-------------------------------------------------------
SF.Net email is Sponsored by the Better Software Conference & EXPO
September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices
Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA
Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf
_______________________________________________
Jmol-users mailing list
Jmol-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jmol-users

Reply via email to