While running, if CenarioVR content is iframed within another project, for example in a Lectora, Captivate, or Storyline course, it posts messages to its parent detailing what is happening in the content. All messages are posted as JSON, and are indexed by the “type” data member. Post Messages can also be sent to the CenarioVR content to set variables and run actions, allowing you to script the content from an outside frame.

Messages sent from CenarioVR to its parent Frame

ATTEMPTED

Sent once at the start of a session

  • type - cenariovr:attempted
  • scenario - (name of scenario)

EXPERIENCED

Sent for each time a scene is visited

  • type - cenariovr:experienced
  • scenario - (name of scenario)
  • scene - (name of scene)
  • duration - (# of seconds in scene)

CLICKED

Sent each time an object is clicked on in a scene

  • type - cenariovr:clicked
  • scenario - (name of scenario)
  • scene - (name of scene)
  • object - (name of object clicked on)

DRAGGED

Sent each time an object is dragged in a scene

  • type - cenariovr:dragged
  • scenario - (name of scenario)
  • scene - (name of scene)
  • object - (name of object dragged)

DROPPED

Sent each time an object is dropped in a scene

  • type - cenariovr:dropped
  • scenario - (name of scenario)
  • scene - (name of scene)
  • object - (name of object dropped)
  • dropzone - (name of dropzone, or not defined for no dropzone)

SPUN

Sent each time an object is spun in a scene

  • type - cenariovr:spun
  • scenario - (name of scenario)
  • scene - (name of scene)
  • object - (name of object spun)

ANSWERED

Sent each time a question is answered

  • type - cenariovr:answered
  • scenario - (name of scenario)
  • scene - (name of scene)
  • questname- (name of question)
  • questtext - (text of question)
  • choicetext - (text of selected choice)
  • iscorrect - (true or false)
  • duration - (# of seconds to answer question)

UPDATED

Sent each time a variable is updated

  • type - cenariovr:updated
  • scenario - (name of scenario)
  • scene - (name of scene)
  • variable - (name of variable)
  • value - (value of variable)

FINISH

Sent once at the completion of a session

  • type - cenariovr:finish
  • scenario - (name of scenario)
  • score - (percentage relative to 100)
  • result - (completed,passed,failed)
  • duration - (# of seconds to complete scenario)
  • variables - (an array of name value pairs)
  • name - (name of variable)
  • value - (value of variable)

Sample JavaScript to catch messages from CenarioVR content

window.addEventListener('message', function(event) {
   var data = JSON.parse(event.data);
   var messagedatatype = data.type;
   if (messagedatatype=='cenariovr:attempted') {
           console.log("Scenario Attempted: " + data.scenario);
   }else if (messagedatatype=='cenariovr:experienced') {
           console.log("Scene Experienced: " + data.scene + ", Duration: " + data.duration );
   }else if (messagedatatype=='cenariovr:clicked') {
           console.log("Hotspot Clicked: " + data.object );
   } else if (messagedatatype=='cenariovr:answered') {
           console.log("Question Answered: " + data.questname + ", Correct: " + data.iscorrect  + ", Duration: " + data.duration );
 } else if (messagedatatype=='cenariovr:updated') {
           console.log("Variable Updated: " + data.variable + " :  " + data.value );
   } else if (messagedatatype=='cenariovr:finish') {
         
var strVars = "";
 for( var index=0; data.variables && index<data.variables.length; index++){
if( index != 0 ) strVars += ", ";
strVars += data.variables[index].name + " = " + data.variables[index].value;
}
  console.log("Scenario Finished: " + data.scenario + ", Score: " + data.score + ", Result: " + data.result + ", Duration: " + data.duration + ", Variables: { " + strVars + " }");
   }
} );

Sending Messages to CenarioVR Content from an Outside Frame

A scenario can also be interacted with from an outside frame by posting messages. Two messages are used, one allows the ability to set a variable's value, the other allows you to run an event, which gives you the ability to perform any action within a scenario. The messages are formatted as follows:

SETVAR

  • type - cenariovr:setvar
  • variable - (name of variable)
  • value - (value to set)

RUNEVENT

  • type - cenariovr:runevent
  • event - (name of event)

Sample JavaScript to send messages to CenarioVR content

function setVar(){      
window.frames[0].postMessage('{"type":"cenariovr:setvar", "variable":"MyVar","value":"3"}', "*");}
function runEvent(){      
window.frames[0].postMessage('{"type":"cenariovr:runevent", "event":"Event1"}', "*");}