Randomize slides with JavaScript (or Advanced Actions)?
i wondering if out there javascript knowledge me out little...
a coworker came me question randomizing slides. we're working in captivate 5.5. slides part of quiz (but not question slides). have click box. idea if user clicks box (or outside box), shows correct (or incorrect) caption , jumps random slide (a new scenario). if user gets end of slide without choosing anything, time runs out , jumped random slide , counts incorrect answer. user must see slides in random order no repeats.
i've created advanced action, incorporating random number widget, , works. problem project has 50 slides, , i'm not sure that's doable advanced actions. is, test 3 random slides has action 4 conditional statements, i'm not looking forward creating 1 50 slides. (i don't know if captivate able handle that.)
is there (easy-ish) way accomplish javascript instead? vague idea based on limited programming knowledge is:
- on entering first captivate slide, create array of slide numbers of random slides - 1 (because cpcmndgotoslide index starts @ 0)
so if had project wanted randomize slides 3-8, array [2, 3, 4, 5, 6, 7] - shuffle/randomize array
- set variable called slideviews = 0 keep track of how many slides have been viewed (and therefore element in random array jump next)
- create function set execute when want jump random slide (either @ end of slide or upon success/failure of clicking box)
something like... if slideviews < array.length, cpcmndgotoslide = array[slideviews]; slideviews++; else, cpcmndgotoslide = 8 (jump end slide)
obviously missing stuff (like proper syntax , necessary things communicate captivate)... logic sound? there better way this?
now think it, array , variable slideviews have saved if wanted work bookmarking... think project scorm 1.2 in lms.
it might nice have user variable can access within captivate project , can put in caption show scenario #. scenario = slideviews (i know isn't syntax, reading jim leichliter's javascript series on captivatedev.com, it's basic idea.)
anyway, pointers helpful! thanks.
edit: i played around little; randomization found code online, , wrote create array automatically , function jumping random slide. here's i've got far (not tested in captivate yet):
var objcp = document.captivate; var randomnumbers = []; // following creates values array: 3 52. // want randomize slides 4-53, using cpcmndgotoslide (index starting @ 0) jump them for(i=3; i<53; i++) { randomnumbers[i-3] = i; } var n = randomnumbers.length; var temparr = []; (i = 0; < n-1; i++ ) { // following line removes 1 random element arr // , pushes onto temparr temparr.push(randomnumbers.splice(math.floor(math.random()*randomnumbers.length),1)[0]); } // push remaining item onto temparr temparr.push(randomnumbers[0]); randomnumbers=temparr; var slideviews = 0; var randomslide = function() { if (slideviews < 50) { objcp.cpeisetvalue("cpcmndgotoslide", randomnumbers[slideviews]); slideviews++; objcp.cpeisetvalue("scenarionumber", slideviews); } //after slides have been seen, jump final results slide else { objcp.cpeisetvalue("cpcmndgotoslide", 53); } };
i doubt this'll work off bat, maybe it's start?
well, feel bit silly talking myself, might post progress.
i forgot comments break javascript in captivate, once sorted out got things working code:
var objcp = document.captivate;
var randomnumbers = [];
for(i=3; i<53; i++) {
randomnumbers[i-3] = i;
}
objcp.cpeisetvalue("array1", randomnumbers);
var n = randomnumbers.length;
var temparr = [];
(i = 0; < n-1; i++ ) {
temparr.push(randomnumbers.splice(math.floor(math.random()*randomnumbers.length),1)[0]);
}temparr.push(randomnumbers[0]);
randomnumbers=temparr;
objcp.cpeisetvalue("array1randomized", randomnumbers);
var slideviews = 0;
var randomslide = function() {
if (slideviews < 50) {
objcp.cpeisetvalue("cpcmndgotoslide", randomnumbers[slideviews]);
slideviews++;
objcp.cpeisetvalue("scenarionumber", slideviews);
}
else {
objcp.cpeisetvalue("cpcmndgotoslide", 53);
}
};
whenever want go next random slide execute randomslide(); , works. can watch cycle through slides 4-53 randomly before jumping 54, final slide. (the lines set array1 , array1randomized can put arrays in debugging captions , follow along. order of slides visited matches order of randomized array.)
questions
i've tried researching this, while i'm rambling here might ask again: there way store randomized array , slideviews variable in scorm data , if user resumes in middle?
is there gained putting code outside swf? @ moment executes upon entering first slide. if did resuming in middle of course work, problem? (ie, if resumes on slide 40, captivate load first slide function can called on slide 40?)
More discussions in Advanced Adobe Captivate Users
adobe
Comments
Post a Comment