Copy link to clipboard
Copied
Hello,
I am trying to create a project in which users first have to answer a questionnaire (survey quiz) with two options each and based on their answers (e.g. if option As chosen is greater than option Bs), they are transferred to a different part of the project.
I tried to achieve this by creating custom variables. I created a variable for A (answerA) and another for B (answerB) and then wrote the script below for it.
if (cpQuizInfoAnswerChoice == A) {
answerA++;
}
else {
answerB++;
}
I then executed this script on the "on Enter" event for each slide in the quiz.
On the "Quiz Results" page, I executed an advanced action
The problem is that this does not seem to be working. I previewed it on my browser and after answering the questions, it directed me to slide 2. I assumed it was working since i purposely selected more option Bs and had specified "jump to slide 2 if answerB is greater than answerA". But then I took the quiz again but this time, I selected more option As but still it jumped to slide 2 instead of slide 1 as i specified.
Please can anyone tell me what I am doing wrong?
Thank you.
Copy link to clipboard
Copied
First you need to get the Captivate object to access the variables, and turn the variable into a number:
var cpObj = document.getElementById('Captivate');
var myChoice = cpObj.cpEIGetValue('m_VarHandle.cpQuizInfoAnswerChoice');
var ansA = parseInt(cpObj.cpEIGetValue('m_VarHandle.answerA'));
var ansB = parseInt(cpObj.cpEIGetValue('m_VarHandle.answerB'));
if (myChoice == A) {
ansA++;
cpObj.cpEISetValue('m_VarHandle.answerA', ansA);
}
else {
ansB++;
cpObj.cpEISetValue('m_VarHandle.answerB', ansB);
}
Also, if you execute the script on slide enter, it will return the answer of the last question answered.
Copy link to clipboard
Copied
Thanks for replying.
Am I to insert all the code above in each question slide like this?
And since my "On slide exit" option is greyed out, I opted for "on slide enter". Is my method of using the advanced action on the quiz results page adequate? Or can you please suggest a better way for me to achieve this?
Thanks again.
Copy link to clipboard
Copied
Your advanced action should be fine.
I didn't test the code I wrote but it should work.
If your decision to jump to different slides is on the first slide after the last quiz I think you'll need to execute the JavaScript from the advanced action and then make the decision based on the variable values.
Copy link to clipboard
Copied
I tried everything as you suggested but it does not seem to be working. It still takes me back to slide 2 regardless of what option is chosen more.
Copy link to clipboard
Copied
The variable cpQuizInfoAnswerChoice is only available for a split second, then it is reset.
I think you are going to need to find a way to evaluate points scored.
Copy link to clipboard
Copied
Really? I have the experience that cpQuizInfoAnswerChoice keeps its value until the next question is submitted. I have been using it in many use cases.
Copy link to clipboard
Copied
Yep, I was alerting the values and it came up empty, then I put the variable in a Smart Shape and you could see it reset a split second into the next slide.
Copy link to clipboard
Copied
I'm always capturing that value On Enter for the next slide. And then it is still there. Because you are starting a new question, it will be reset soon.
Copy link to clipboard
Copied
You'd think it would still be there since it is not set until slide enter anyway. Might be a bug of some kind. I've had the same issue trying to capture it in a widget.
Copy link to clipboard
Copied
About which version are you talking? It worked perfectly in previous versions, but checked just now in 7.0.1 and you are right. Have to check in CP8. Bummer, what has changed there?
Moreover, when I capture the answer with the Success/Failure actions, the user variable is populated, but it is cleared together with cpQuizInfoAnswerChoice.
Another blog post that I have to take off line. Time to stop totally with blogging, I'm afraid.
Copy link to clipboard
Copied
Latest version of 7, I haven't checked 8 yet either. Makes the variable kind of useless.
Copy link to clipboard
Copied
Indeed, I used to check most of my blog posts with each release, but didn't do it last time. This was a blog post that was visited quite a few times, now it is again unusable. Will check on CP8, but suspect it will be the same. It has no sense whatsoever to expose a system variable that you cannot use.
Same situation in Captivate 8. I will log a bug.
Copy link to clipboard
Copied
I just checked v6 and it's doing the same thing.
Copy link to clipboard
Copied
I don't have 6 anymore... thanks. Just logged a bug. And there are more articles where I used this system variable