Picking cards from a deck

Feb 11, 2021

Hello there!

I wanted to create a card drawing simulation in Storyline. The objective is to have four decks of cards that the user can choose between. By clicking on any of them, the user is presented with some question that they have to answer. Then they go back to the main view and pick a card again (from any deck).

The most problematic part for me is that I want the card to be randomly generated each time the user clicks on any deck. I have the question banks set up for each deck, but only one question from each is being drawn, no matter how many times I click on the deck. The questions seem to be picked when opening the preview, since when I turn it off and on again, new ones are generated.

I tried setting up triggers, variables, but nothing seems to work. Does anyone have any idea how to implement such random card picker, or maybe there's a feature I'm missing that could help me?

Thanks in advance for any suggestions :)

4 Replies
Maria Costa-Stienstra

Hi, Barbara, and welcome to E-Learning Heroes! ✨

There are several ways we can approach your scenario (and I am hoping some of our talented users can chime in here to offer their suggestions), depending on how/if you want the results to be calculated, how many times the learner can "pick a card", etc. 

When you are using a random question from a bank, the usual way is to set up each question in a different slide. For example, if you want three randomly generated questions, then you create three different slides. In your scenario, if you try to loop back to the first slide where the learner picks a card, then they are just going back to the same random question each time. 

My solution would be to duplicate that first slide throughout the scene, with the questions in between, branching from each of the four decks. I am attaching a sample .story file with two decks and two questions each, and I also created a short video showing you what I did.

Let me know if this works for you!

Barbara Blotniak

Maria,

Thank you so much for your response, I think I finally fully understand how the question banks work!

Also, the example you shared is a brilliant solution to my problem, so thanks for that too:)

One other thing though, is there an option to exclude from the draw the cards that have been previously picked?

Erin Flage

I created a game that used a random card draw (think Community Chest in Monopoly).  How I accomplished this is to create a scene for each deck and build each card as a slide.

I created a text variable to represent each of the cards (1,2,3,4,5,...)

Then on my main gameboard slide, if the user selected the card pile (to draw a card), I executed some Javascript to split my text variable into an array, shuffle the array and pop the last number (simulating the draw), and then update my variable with new list.

Here's the javascript I used:

var cards = GetPlayer().GetVar("Cards").split(","); //get variable from SL and create array
cards.sort ( () => .5 - Math.random() ); //shuffle the array
GetPlayer().SetVar("SelectedCard", cards.pop()); //pop the last number and return to SL
GetPlayer().SetVar("Cards", cards.toString()); //update the "deck" in SL

Then I have a trigger for each card based on the value of "SelectedCard"

For example,

Lightbox Slide Card1

When user clicks Draw card

if SelectedCard = 1