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

Try this code:

var lesson_status; [COLOR="Green"]// Declare variable.[/COLOR]

setTimeout ([COLOR="SandyBrown"]function() {[/COLOR]

	lesson_status = api.LMSGetValue("cmi.core.lesson_status"); [COLOR="Green"]// Get the value![/COLOR]

	alert (lesson_status); [COLOR="Green"]// What to do after 2 seconds...[/COLOR]

[COLOR="SandyBrown"]}[/COLOR], 2000);

You need to create a function to parse as setTimeout, not a call!

Hmmm…

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

Maybe I should explain better 1st :slight_smile:

I have 3 functions actually:

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