Selecting random items from a list and displaying the selected items alone in order

May 10, 2018

Hi,

I got stuck!!! I have a list of items say around 10 with respective check boxes and prices. I should be able to select say 5 items randomly from that list and display it in order.

For example i can select items 2, 5, 7, 8 and 10 and then on clicking submit button, it should take me to a different page where my selected items are arranged in order (1, 2, 3, 4 and 5 ) with names and price. The trick part is that it should not be java-scripted or any other external script.

Help me pleaseeeeeeeeeeeee!!!

Regards,

Senthil R

8 Replies
senthil arul arasu R

Hi Len,

Thank you for the quick response.

Drag and drop would look like a different interactivity for the user. I need the user to just select using a check boxes and click a submit button which will take him/her to a different page where the selected items will be listed in an order. Please find the screen shots attached.

Walt Hamilton

With a short javascript, about 2 minutes. Without it about a million VERY carefully constructed triggers. I just cobbled this up off the top of my head, so when you try it, there may be some steps that are missing or need to be tweaked. The idea is that it starts at the bottom of the list of options that you have and if that item is chosen, puts it in the first spot of the final list. Then it moves up the list of potential choices, and when it gets to the top, the first spot in the final list contains the chosen item that is highest on the list of potential choices. It marks it so it won't be used again, and repeats the process for item two on the final list.

 It would look like this:

 

 
On first slide, the potential choices are listed and named PotentialChoiceX where X = 1 – 10, and they each have a selected state. LastItemUsed is created as a number variable with a value of 0. When you have made all your selections, you continue to a layer, where the work is done with these triggers that fire when timeline starts:


      1. Adjust variable ItemChosen1 Assign (text for PotentialChoice10) on condition PotentialChoice10 state is selected
     2. Adjust variable LastItemUsed Assign 10 on condition PotentialChoice10 state is selected

Repeat triggers 1 and 2, changing the number in bold for numbers 10 – 1. The numbers must be in this order.

 Adjust variable ItemChosen1 Assign (text for PotentialChoice9) on condition PotentialChoice9 state is selected
Adjust variable LastItemUsed Assign 9 on condition PotentialChoice9 state is selected

Once you have gone through triggers 1 and 2 for all the choosable items 1 – 10, the variable ItemChosen1 will contain the text for the selected choice with the lowest number; the top one chosen.

Now add these triggers so that choice will not be used again:

      3. Change state of PotentialChoice10 Normal on Condition LastItemUsed = 10

Repeat trigger 3, changing the number in bold for numbers 10 – 1. The numbers must be in this order.

Change state of PotentialChoice9 Normal on Condition LastItemUsed = 9

 Add this trigger to end the process when you use the item 10so you don’t have to go through all the triggers:

     4. Jump to Next slide on condition LastItemUsed = 10


And there you have it. Repeat these 31 triggers (1, 2, and 3 for each of the 10 PotentialChoices, and 4 once at the end), changing the X in references to ItemChosenX from 1 to 10.

On the Next slide put ten Reference boxes, with the variables ItemChosenX, where X is 1 – 10, and when you jump there, they will be filled

Two hints to make it go faster

1. When you write the triggers for ItemChosen2, you do not need to include PotentialChoice1. If it had been selected, it would have been used for ItemChosen1. So each set of triggers will only need to check a decreasing amount of items, until you reach #10, which only has to check #10

2. There is the potential this could be easier to create if you create the triggers for ItemChosen1 on Layer1 and make the very last trigger show Layer2. Then Duplicate Layer1 to create Layer2. All the triggers will be copied over, and you just have change the references from ItemChosen1 to ItemChosen2. Try it, it may or may not be easier for you.

 

Bradley Eader

Hi and thank you for getting this started Walt! There was one issue I found with the javascript, so to get it working the == "true" part needed to have the quotes removed: var player = GetPlayer();
var correct =[];
var inCorrect =[];
var selections =[];
var j=1;
var k=1;

var NOP = ["", "Jaw Thrust maneuver", "Oropharyngeal airway", "Nasopharyngeal airway", "King (multi-lumen) airway", "Laryngeal Mask Airway (LMA)", "Endotracheal tube", "Cricothyroidotomy"];


selections[1] = player.GetVar("JawThrust");
selections[2] = player.GetVar("Oro");
selections[3] = player.GetVar("Naso");
selections[4] = player.GetVar("King");
selections[5] = player.GetVar("LMA");
selections[6] = player.GetVar("ET_Tube");
selections[7] = player.GetVar("Crico");


for(i = 1; i < 8; i++){
    if (selections[i] == true) {
    correct[j] = NOP [i];

    j++;
    }  else {
       inCorrect[k] = NOP[i];
    k++;
    }
    }

for(i = 1; i < 8; i++){
    if (correct[i] != null) {player.SetVar("Correct" + i, correct[i]);}
     if (inCorrect[i] != null) {player.SetVar("Incorrect" + i, inCorrect[i]);}
              }