Skip to main content
Known Participant
May 10, 2021
Question

Captivate 2019 - memory game with advanced actions and javascript

  • May 10, 2021
  • 2 replies
  • 1438 views

I'm working on a memory game using advanced actions. I have managed to create items, make them flip (applying effects), create variables, and make them change their states when clicked. However, I can't figure out the advanced actions to check for pairs matched and shuffle items when a game restarts. Has anyone done this using advanced actions? or maybe advanced actions and javascript? 

This topic has been closed for replies.

2 replies

Stagprime2687219
Legend
May 10, 2021

Perhaps this will help get you started.

You will need several variables to do this.

I would use two variables to track which of the two turns is active (firstPick and secondPick) and two more to store the values of those selections (tileValueA and tileValueB)

You will also need a variable that tracks the current selection in order to transfer it to the variables that will be compared.

Suppose you have a 4x4 grid of 16 tiles to play.

Each tile will have a pickValue from 1 to 16.

Each tile will have a tileValue as well but there will be 8 matches - two of each value.

Maybe you have a picture of a bird on two of the tiles - the tileValue might be set as "bird" for tiles 3 and 11.

 

tile 3 

pickValue=3;

tileValue="bird";

setValues();

tile 11 

pickValue=11;

tileValue="bird";

setValues();

 

The selection process might look like this

The user selects the first tile... code runs

if (firstPick==0) {       // checks to see if the first pick has been made - in this case -NO

firstPick=pickValue;   // because our variable was 0 - this will now be set to 3

tileValueA=tileValue   // the tileValueA variable will now match the value of the selected tile "bird"

}

// when the second choice is made, the firstPick value will not be 0 so this will run

else {

secondPick=pickValue;  // our second pick is now going to be set to 11

tileValueB=tileValue;     // our tileValueB can now be set to "bird" as well

}

compare();    // this is a function to see if tileValueA is equal to tileValueB

In this function, you will want to either flip the tiles back over for a non-match or remove them from the game board if they are. I would also take the script logic for tile selection and value setting and make it a function to minimize your code.

 

If you wish to randomize the gameplay - it gets a little trickier as you need to find a way to randomize the tile backs.
I would suggest using some arrays in the background for that.

 

Here are a couple examples - both of which have randomization for endless playability.

The first is strictly Memory - it has a visual shuffling element

https://elearning.adobe.com/2019/10/memory-game-part-1-chemmem/

 

The second project has a memory game a few slides in.

It is randomized but no visual shuffling.

https://elearning.adobe.com/2021/03/temperature-conversions/

 

Both are advanced level Memory games rather than the traditional picture match.

 

Anyway - hopefully this gives you something to chew on.

grcutzAuthor
Known Participant
May 10, 2021

Thanks Stagprime.

 

I'll try your suggestions and see what happens. I appreciated your time and sample provided. 

 

I tried one of your memory games. It is very interesting. Congratulations.

Lilybiri
Legend
May 10, 2021

You will need JS id you want to be able to shuffle the cards. If you want to try with shared actions, and a fixed positio here is the third version of a memory game. First version was created 8 years ago, and to see how easy it had become with the recent features I refurbished it:

http://blog.lilybiri.com/lets-play-and-dream

 

 

grcutzAuthor
Known Participant
May 10, 2021

Thank you Lilybiri for replying.

 

I'm fairly new to Captivate (almonst two months). Would you mind sharing a sample of the advanced actions you used? If you did it without other languages like JavaScript, it means Captivate comes with the options to do it. 

 

 

Lilybiri
Legend
May 10, 2021

You seem to like the JS approach, why not use that? I used shared actions, but explained that you will feel limited. It was rather easy to create that memory game, and I know also how to extend it. But you got full explanations from Greg. No need to try both.

If you want to try the shared action,  look at:

http://blog.lilybiri.com/memory-game-setup-version-2021

Just FYI: Advanced and Shared actions are converted to JS on runtime. However you don't need to remember syntax rules nor programming terms with the point-and-click approach. It is more limited than pure JS, but can achieve a lot more than most users think. Shared actions are great for reuse within one project and in multiple projects because they use parameters instead of fixed objects/states/....