How to pick 8 images randomly and deal on the playboard

jorlindjorlind Member, PRO Posts: 7
I have 20 images. From these 20 images i want 8 images to be assigned, either randomly or with a table. The eight images chosen are dealed on the playboard using allready defined locations from another table.
If I press a refreshbutton, 8 new photos from the 20 will show up instead.

I have been based the dealing on the GSHelper tutorial http://gshelper.com/?p=545
But in that tutorial Tshirtboot layout all the cards he has.

Can someone pleace help me how to think or give a complete solution.
Thanks in advance.

Jorgen from the north of Sweden

Best Answers

  • MobileRocketGamesMobileRocketGames Posts: 128
    edited November 2012 Accepted Answer
    This is what you want.
    Randoms without repeats.
    http://arcade.gamesalad.com/game/1621
  • tatiangtatiang Posts: 11,949
    Accepted Answer
    I merged your two discussions. You can use the video above to pull a random number from a table. Then it's just a matter of using the behavior I listed below the video to convert the number to an image name. Have you tried that?

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • MobileRocketGamesMobileRocketGames Posts: 128
    edited November 2012 Accepted Answer
    @jorlind Oh I am terribly sorry, I didn't know that community templates were down and you wouldn't be able to download that game template or watch it :((
    I can think of a couple ways to do what you want but none of them will be easy.
    But since you've already marked my response as an answer I feel obligated to give you a hand.

    The best way of accomplishing what you want is to create two tables, one with 20 rows, the other blank (name them NumberTable and BlankTable).
    In the table with 20 rows, type 1-20 ascending (or descending, whatever) in rows 1-20. Then create 8 game.attributes and name them Number1 to Number8.

    Create a integer game.attribute, call it "Randomizer".

    Then open your button actor (the one that deals the cards) and create a Rule (on touch and/or the other events needed to draw the random cards):
    • Copy Table NumberTable to BlankTable
    • Change Attribute game.Randomizer to random(1,tableRowCount(game.BlankTable))
    • Timer (after.05s)
      • Change Attribute game.Number1 to tableCellValue(game.BlankTable, game.Randomizer, 1)
      • Add/Remove Row Table: BlankTable, Action: Remove Row, At Index: game.Randomizer
      • Change Attribute game.Randomizer to random(1,tableRowCount(game.BlankTable))
    • Timer (after .1s)
      • Change Attribute game.Number2 to tableCellValue(game.BlankTable, game.Randomizer, 1)
      • Add/Remove Row Table: BlankTable, Action: Remove Row, At Index: game.Randomizer
      • Change Attribute game.Randomizer to random(1,tableRowCount(game.BlankTable))
      etc, etc.
    I've highlighted in red the important parts that need to be changed for each timer group. There should be 8 of those timer groups in total. As you can see, I've increased the time by .05 of a second. So in total it will take .4s or almost half a second to finish (you should have some sort of card drawing animation anyway, so this should be fine). Normally I wouldn't recommend timers but as this is already pretty complex for a new user it will have to do.

    What this is doing is creating a random number between 1 and the number of rows left in the table. Each time it rolls a number it removes a row from the table. This is necessary so that it doesn't call on row 19 or 20 when there are only 15 rows in the table and crash the game. So even if it rolls 13 twice in a row, the value in row 13 changes from 13 to 14 after row 13 is deleted.

    Once you have 8 of those timer groups you will have game.attributes for the all cards (8 in this example) that you need, with no duplicates.

    Next is just a matter of telling the engine card1 = game.Number1, card2 = game.Number2, etc, etc.

    Thats pretty much it.
    If that was helpful you can rate this post as insightful :D

Answers

  • jorlindjorlind Member, PRO Posts: 7
    Thank you for your answer!
    I have tried to look at it but, I can not get it going.
    Do you have any trix.
    Yes I have the plug in=)

    Jorgen
  • jorlindjorlind Member, PRO Posts: 7
    I am not able to see http://arcade.gamesalad.com/game/1621 and other helpers.
    Can you see it?

    Jorgen
  • LeonardDeveloperLeonardDeveloper Member Posts: 4,630
    Hello Jorgen,
    these helpers are made for a very old version of the GS Arcade, I'm not even sure they work anymore...
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    edited November 2012
    Agreed that those aren't going to work any more. You might use if that's what you need, and then use Change Attribute self.image to game.number..".png" to change the actor's image to a file with the name 1.png, 2.png, etc.

    @tshirtbooth has a bunch more useful tutorial videos at http://gshelper.com.

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • jorlindjorlind Member, PRO Posts: 7
    Thank you for your reply!
    I have seen almost every tutorial from gshelper.com.
    The problem comes when you are going to put a few tutorials together and do something on your own.

    I have 20 images. From these 20 images i want 8 images to be assigned, either randomly or with a table. The eight images chosen are dealed on the playboard using already defined locations from another table.
    If I press a refresh-button, 8 new photos from the 20 will show up instead.

    I have been based the dealing on the GSHelper tutorial http://gshelper.com/?p=545
    But in that tutorial Tshirtboot layout all the cards he has.

    Jorgen from the north of Sweden

  • jorlindjorlind Member, PRO Posts: 7
    Thank you for answers.
    They made my day! >:D<
Sign In or Register to comment.