Forum Discussion

ThaddeusAshclif's avatar
ThaddeusAshclif
Community Member
3 years ago

Dealing with large number of triggers/varriables and states - Using Cards

I've been thinking about using cards for a gamified activity. 

There are a few things that I would like some help with as the methods that I can think of are very inefficient. 

Storing states. 
Every time a card is drawn it must be recorded as no longer available.  Normally I would have a series of triggers the size of my deck.  However having this many triggers causes issues. 

I can solve the issues with playing cards and the hand.  For this I would create objects with as many states as there are card types.  Annoying to maintain but doable.   To record the states of the objects each would have a variable.  This could also get large if the number of objects reaches a certain size as ever possible play position would have to be designed for.

 

  • The biggest problem is keeping track of which cards have been used, unless you want to always follow the same order. If you want to use a random order, without repeating any cards until they have all been used, there is no way SL can do that. So you need to use JS. I would create an array and sort all the cards into it randomly. You would need either to delete each card from the array as it is chosen, or use a variable in SL to keep track of where you are in the array. I would execute the JS every time I wanted a new card and have it  change a variable in SL to match the chosen card ( 1-52). The card pile would have 52 states, and every time the variable changed, a series of triggers would change the state of the pile to match the variable number.

  • You can use text fields in Storyline as arrays... Here is an old sample of mine showing how you can setup a textfield in Storyline to act as an array.

    https://360.articulate.com/review/content/2641479d-6c12-47a8-b741-f24d537a39de/review

    When you showed some element of the array, its easy to remove with this code..so it never will show again.

    var array = [1,2,3,4,5,6,7,8,9,0];
    function arrayRemove(arr, value) { 
        
            return arr.filter(function(ele){ 
                return ele != value; 
            });
        }
        
        var result = arrayRemove(array, 6);
        // result = [1, 2, 3, 4, 5, 7, 8, 9, 0]