SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Hybrid View

  1. #1
    SitePoint Enthusiast
    Join Date
    Apr 2006
    Posts
    26
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    setTimeout() calling function that has a return value

    Hopefully I am just missing something easy here. I am trying to call a function with the setTimeout, but the function returns a value. How do I get the value returned.

    var lesson_status = api.LMSGetValue("cmi.core.lesson_status"); //without a delay

    setTimeout(api.LMSGetValue("cmi.core.lesson_status"),2000); //wait 2 seconds then call api.LMSGetValue

    What I need is something like:
    var lesson_status = setTimeout(api.LMSGetValue("cmi.core.lesson_status"),2000); //lesson_status then contains a reference to the timer

    I also tried something like this:

    setTimeout(retValue=api.LMSGetValue("cmi.core.lesson_status"),2000); //wait 2 seconds then call api.LMSGetValue and set retValue to its return value

    What I need is to call the function LMSGetValue("cmi.core.lesson_status") after a 2 second pause and get its return value.

    TIA,
    Victor

  2. #2
    SitePoint Zealot the DtTvB's Avatar
    Join Date
    Jul 2006
    Location
    Thailand
    Posts
    162
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try this code:
    Code:
    var lesson_status; // Declare variable.
    
    setTimeout (function() {
    
    	lesson_status = api.LMSGetValue("cmi.core.lesson_status"); // Get the value!
    
    	alert (lesson_status); // What to do after 2 seconds...
    
    }, 2000);
    You need to create a function to parse as setTimeout, not a call!

  3. #3
    SitePoint Enthusiast
    Join Date
    Apr 2006
    Posts
    26
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hmmm...

    If possible can you explain how I could use this a little better.

    Maybe I should explain better 1st

    I have 3 functions actually:
    Code:
    var LMS_lesson_status = api.LMSGetValue("cmi.core.lesson_status");
    var LMS_lesson_mode = api.LMSGetValue("cmi.core.lesson_mode");
    var LMS_lesson_location = api.LMSGetValue("cmi.core.lesson_location");
    What I am trying to do is pause 2 seconds between each call to the api.LMSGetValue method.

    Sorry for the extra explanation.

    -Victor


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •