How Do I Insert AnimName into Array Loop?

Get help using Construct 2

Post » Mon Jan 25, 2016 12:59 am

I am experimenting with the card shuffling code presented in the following tutorial: https://www.scirra.com/tutorials/469/im ... -algorithm.

I have set up my card deck as a sprite called obj_HeroDeck. This sprite has 10 separate Animations, called, "ID_H01_CardName," "ID_H02_CardName," "ID_H03_CardName," etc.

Each of these animations is a specific sprite of a playing card within the deck.

Image

As the array is randomized, how do I insert the names of the different animations into the array loop so that the animation names can be called for use in a function?

Image
Last edited by DigiLusionist on Mon Jan 25, 2016 11:41 pm, edited 3 times in total.
Check out "Extraordinary!" the Superhero Card Game: www.armchairadventuring.com
B
14
S
2
Posts: 35
Reputation: 1,323

Post » Mon Jan 25, 2016 2:47 pm

Another question:

Would it be better to set up the card deck as a sprite with its cards imported as Animation Frames, instead?
Check out "Extraordinary!" the Superhero Card Game: www.armchairadventuring.com
B
14
S
2
Posts: 35
Reputation: 1,323

Post » Mon Jan 25, 2016 5:57 pm

Hello,

Would it be better to set up the card deck as a sprite with its cards imported as Animation Frames, instead?
It does not really matter. If you want to animate your cards at some point, the solution with different animations is better. If you don't need animations, then using frames might be a tad easier.

The while loop and there especially how the i is set up and how it uses global variables make me cringe a bit. So I use code with a for loop instead that's less error prone and imo easier to grasp, because everything is at one place in my example (also it is a function as it should be, since you want the shuffling to be reusable):

https://copy.com/QXGb4317KtymzkQ9
Image

What should interest you the most is probably the event that creates the cards and sets the animations.
For example you could write (with your names mentioned up top):
"ID_H"&zeropad(deck.curvalue, 2)&"_CardName"

Problem: if you want to fill in the CardName with an actual card name, this won't work anymore.
In that case you will need a dictionary or another array, where you store the name, which then you can let C2 read, when it's time to set the animation.

I'm not sure what kind of properties your cards will end up with. There is also the possibility to just fill an array with all the information, each card has its own x, and then y = 0 would be card name, y = 1 would be animation name and so on. You can read in stuff like this even from a csv file. Just be aware that importing the data from csv will import numbers as string, if you don't explicitly convert them upon adding them to the array.
Visual Novel 'Engine' in 100 Events
if you ever have to choose between buying Construct 2 on scirra.com or on Steam, read this: Review
B
22
S
9
G
1
Posts: 788
Reputation: 3,788

Post » Mon Jan 25, 2016 6:14 pm

mindfaQ, thank you very much for the reply. I will study your .capx file, and consider what you wrote above.
Check out "Extraordinary!" the Superhero Card Game: www.armchairadventuring.com
B
14
S
2
Posts: 35
Reputation: 1,323

Post » Mon Jan 25, 2016 11:47 pm

Problem: Using the method suggested, I am getting duplicates of cards from randomization. I need non-duplicating results.

To create one of the two draw decks, I am now trying the following:

Importing all of the playing cards into the "Draw Deck" sprite object as Animation Frames (instead of as separate animations).

Image

The actual playing cards will have different images (as opposed to the numbered cards I am using for testing the shuffling). And, they need to have UIDs.

I assume I have to use an array to load the animation frame images into before the cards are shuffled.

Question: How do I import the animation frame images into an array (called, array_HeroesDeck) and then randomize the position of the animation frames within the deck array so they can then be drawn in order during the course of the game?
Check out "Extraordinary!" the Superhero Card Game: www.armchairadventuring.com
B
14
S
2
Posts: 35
Reputation: 1,323


Return to How do I....?

Who is online

Users browsing this forum: batto, bclikesyou, Lancifer and 25 guests