Copy link to clipboard
Copied
Hey,
in the first Slide of my Projekt I´m executing a Javascript code in the Script Window to generate random questions that are stored in an array and then go to the next slide. In the next slide I want to use the same array to generate a new random question and delete the previous one so that it can appear only one time.
How can I get and set javascript Variables - that are difined in the Script Window on a slide - from other sliders ?
any help would be appreciated ^^
You need to create and initialize the variable in Captivates variables window. Then set the variable like this:
window.randQuestions_List = [ "What is one important skill that you think everyone should have?",
"There are now 25 hours in a day! How do you spend your extra hour?",
"What was the most fun thing you did last weekend?",
"What is one thing you are looking forward to doing when you retire?",
"What is one of your greatest achievements?",
"If you could change one thing about your job, w
...
Copy link to clipboard
Copied
Not sure to understand your problem, which may be due to a language problem. You can write in your language, translation is possible in this forum. Personally I do understand a couple of languages besides English (not my mother tongue).
I suspect you want to override the default setup for random questions, to avoid the need to restart a session to get another batch of random questions. Is that correct?
You didn't post the JS code you are using, you added the tags Advanced actions: how do you use this, which type of items do you have in the array (you cannot have complete slides AFAIK)? Do you transfer the value for variables generated by JS to Captivate variables? Just some questions which may help you to clarify your request.
Here is a recent post I wrote about randomization in Captivate:
https://blog.lilybiri.com/randomizing-in-captivate
This older post talks about the possibilities and limitations of random questions:
https://blog.lilybiri.com/random-questions-dos-and-donts
Copy link to clipboard
Copied
this is the code that I´m using to generate the random question:
var randQuestions_List = [ "What is one important skill that you think everyone should have?",
"There are now 25 hours in a day! How do you spend your extra hour?",
"What was the most fun thing you did last weekend?",
"What is one thing you are looking forward to doing when you retire?",
"What is one of your greatest achievements?",
"If you could change one thing about your job, what would it be?"
];
var randQuestion = randQuestions_List[Math.floor(Math.random()*(randQuestions_List).length)];
window.cpAPIInterface.setVariableValue('hzdRandQuestion', randQuestion);
//remove Item from the Array
const index = array.indexOf(randQuestion);
if (index > -1) { // only splice array when item is found
randQuestions_List.splice(index, 1); // 2nd parameter means remove one item only
}
//go to the next slide
window.cpAPIInterface.setVariableValue('cpCmndGotoSlideAndResume', 2);
In the next Slide I want to use the same Array but the previous Question should be deleted so that it does not appeare another time. the Goal is to generate random Quations in each slide without repeating the question.
The Problem is that i cant get to the same array and I have to redifine it to use it in the script window.
thank you for your help ^^
Copy link to clipboard
Copied
You need to create and initialize the variable in Captivates variables window. Then set the variable like this:
window.randQuestions_List = [ "What is one important skill that you think everyone should have?",
"There are now 25 hours in a day! How do you spend your extra hour?",
"What was the most fun thing you did last weekend?",
"What is one thing you are looking forward to doing when you retire?",
"What is one of your greatest achievements?",
"If you could change one thing about your job, what would it be?"
];
Copy link to clipboard
Copied
I will leave the JS part to our great guru, TLCMediaDesign.
With the Captivate part I can offer some tips:
You didn't answer all my questions in my previous content, only the one asking for the script.
Copy link to clipboard
Copied
Hey,
Copy link to clipboard
Copied
OK, but since you use an advanced action, why do you not add the simple command 'Go to Next Slide' instead of using the system variable in the JS window.
You are creating a sort of Survey, but do not want to have it reported at all. Showing the result of the questions on a summary slide is only meant for the learner. If you want to report to a LMS your approach wouldn't work.