Using Advanced Random's Permutation Tables

12

Index

Features on these Courses

Attached Files

The following files have been attached to this tutorial:

.c3p

ar-permutation-table-card.c3p

Download now 80.19 KB

Contributors

Stats

4,541 visits, 9,349 views

Tools

Translations

This tutorial hasn't been translated.

License

This tutorial is licensed under CC BY 4.0. Please refer to the license text if you wish to reuse, share or remix the content contained within this tutorial.

Published on 26 Aug, 2021. Last updated 5 Jan, 2023

The project we're going to build in this tutorial is simple enough, but it shows how permutation tables can work nicely. You'll need to add eight objects to your project (although one of them is for decorative purposes only and is therefore optional.)

  • AdvancedRandom – we need this plugin to actually create the permutation table
  • AJAX – in order to show the permutation table is working correctly, we need to load an array containing the names of the cards. AJAX is used for this.
  • Array – we hold the names of the cards in an array so we can call them later to make sure the current card number matches the one on display.
  • CardPile – this is an optional sprite of the card back. All it does is make it look a little bit like there's a pile of cards underneath our face-up card.
  • FaceUpCard – this sprite holds all of the cards as animation frames and is used to show the current card in the permutation table. It uses the Tween behavior to animate swapping the current card.
  • Mouse – the project is controlled with the mouse, could be interchanged with the Touch plugin.
  • NextCard – clicking this sprite calls the next card in the permutation table.
  • Text – this is used to show what the current card being displayed should be (it should match FaceUpCard's animation frame) and how many cards are left in the deck.

Because the project is very small and pretty simple, I've set both the viewport size and the layout size 640x640 just to reduce excess space, but again, totally optional. The FaceUpCard is stacked on top of the CardPile sprite in the top half of the viewport with the NextCard button underneath. The Text object is placed on the left-hand side as an information display.

The final bits to add before the events are a pair of global variables and a project file. The two variables are CardNumber, which is a global number with an initial value of 0 and FirstCard which is a global Boolean, initially set to True. The project file is an array with the names of each card in a standard 52 card deck in the Y=0 row.

  • 5 Comments

  • Order by
Want to leave a comment? Login or Register an account!
  • Hey, I want to create a set of numbers, and pick a random number from the set. Then I want to assign each number from the set to a sprite, so that if the table picks a number, then the sprite will pop up or do a action. How do I do that?

      • [-] [+]
      • 1
      • Laura_D's avatar
      • Laura_D
      • Construct Team Community Manager
      • 1 points
      • (0 children)

      These sorts of questions are best asked in the forums really, but as a basic example, you could create the permutation table on the start of the layout, then when a key is pressed you'd iterate through a 'For' loop the same size as the permutation table to spawn that many sprites and assign them an animation frame that matches the loopindex.

  • Hello, thanks for the tutorial it's super useful ! Is there any way to chose the animation of the FaceUpCard the same way we chose the frame ? For example, if I want to make a moving animation for each card, I would create multiple animations on the same object and just call the right one with the matching AdvancedRandom.Perutation(CardNumber), but it does not seem to be possible since changing the animation requires its name, and not a number. Is there a way to do that ? Thanks in advance

      • [-] [+]
      • 2
      • Laura_D's avatar
      • Laura_D
      • Construct Team Community Manager
      • 2 points
      • (0 children)

      There is a system expression to turn an integer or float into a string - try adding str() around the Advanced Random expression.

  • ótimo, obrigado