How to pick 8 images randomly and deal on the playboard
jorlind
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
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
-
tatiang Posts: 11,949I 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
-
MobileRocketGames Posts: 128@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))
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
Answers
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
Can you see it?
Jorgen
these helpers are made for a very old version of the GS Arcade, I'm not even sure they work anymore...
@tshirtbooth has a bunch more useful tutorial videos at http://gshelper.com.
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
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
They made my day! >:D<