Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
0

Sorting or ranking variables in Captivate

Explorer ,
Aug 30, 2021 Aug 30, 2021

Copy link to clipboard

Copied

Good morning all!

I am planning a quiz-type activity in Captivate with a number of personal attributes, and a series of questions to measure your strength against each attribute. At the end of the quiz, I want to disply your highest ranked attribute.

I initially thought this would be easy, I planned to have a variable for each attribute and use an action to increase the score for the attribute variable based on each answer. So, for example:

varAttributeA, varAttributeB, varAttributeC.

Q1: Do you prefer x or y. if x, increase varAttributeA by 1, if y increase varAttributeB by 1.

However I can't see an obvious method of ranking or sorting a set of variables by their value in Captivate. Does anyone know if there is a way to do this, or a good workaround?

 

The best I have come up with so far (on paper) is to have an advanced action with a bunch of conditional tabs comparing one variable to another, then another, and storing the highest variable overall from the set of comaprisons in another variable, and using that to display what I want at the end. But that seems pretty clunky?

Views

419
Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Advisor , Aug 31, 2021 Aug 31, 2021

This can be done with minimal work using a little bit of JavaScript.

 

It may help organize things to create a few more variables for your rankings.

In my small example, I made five variables for the attributes named  varA, varB, varC, varD, and varE

I then created five variables for rank position named rank1, rank2, rank3, rank4, and rank5

 

Over the course of your project - assign points to your variables as needed.

On the last slide where you wish to rank them, you will need to create an array out o

...

Votes

Translate
Community Expert ,
Aug 30, 2021 Aug 30, 2021

Copy link to clipboard

Copied

You are correct that trying to use Captivate's Conditional Advanced Actions to sort values would not result in a very elegant solution.  There are really no built-in functions to do this. 

 

Probably the only way to achieve this would be by using JavaScript.

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Aug 30, 2021 Aug 30, 2021

Copy link to clipboard

Copied

If it helps anyone else, I have settled on this method to identify the variable with the highest value. it can't sort the whole set of variables, and it won't work if tied scores are possible but it is fairly straight forward. You can use the same method with a "less than" comparison to find the lowest scored item.

 

You need 1 conditional tab for each variable. In each tab, it is set up like:

If

variableA > variableB AND

variableA > variableC AND

variableA > variableD AND (and so on for each variable)

Then

variableHighScore = "A"

 

The next tab compares B to all other variables, and if B is highest then variableHighScore = "B" etc.

 

At the end, you can use the value of variableHighScore to show or hide whatever text you want to explain the score.

 

I chose to handle possible ties by giving each variable a unique starting value less than 1. Eg variableA=0.1, variableB = 0.2, variableC = 0.3. Then each question adds either 1 or 0 to that variable. In this way, if for example variableA and variableB end up with 2 points, variableB will be ranked highest because its total value is 2.2. It's not ideal to have the ties settled in a fixed pattern but if you set up questions so ties are very uncommon I don't think it's a big problem.

 

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advisor ,
Sep 02, 2021 Sep 02, 2021

Copy link to clipboard

Copied

LATEST

In case you are interested - I made a working example of this and posted it in the eLearning Community. I have a JavaScript Idea Series and thought this would make a nice little project for that series.

I expanded on the idea a bit by creating a couple of buttons to toggle between sorting from low to high and from high to low. I also included the ability to change the variable values on the fly and re-sort them. 

 

https://elearning.adobe.com/2021/08/sort-variable-values-javascript-idea-series/

 

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advisor ,
Aug 31, 2021 Aug 31, 2021

Copy link to clipboard

Copied

This can be done with minimal work using a little bit of JavaScript.

 

It may help organize things to create a few more variables for your rankings.

In my small example, I made five variables for the attributes named  varA, varB, varC, varD, and varE

I then created five variables for rank position named rank1, rank2, rank3, rank4, and rank5

 

Over the course of your project - assign points to your variables as needed.

On the last slide where you wish to rank them, you will need to create an array out of your variables and then assign your ranks. Place the code as the onEnter action of your slide.

 

I know you found something that works but hopefully this is helpful anyway.

 

// This makes the array regardless of value
var rank = [varA, varB, varC, varD, varE];

// This will sort the array with low value at index 0 and high value at index 4
rank.sort(function(a, b){return a-b});

// This assigns the ranks for display on the slide
// If you want high to low, just reverse 
rank1 = rank[0];
rank2 = rank[1];
rank3 = rank[2];
rank4 = rank[3];
rank5 = rank[4];

 

 

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Help resources