Why each event sheet dont work for each level

Just started using Construct 2? Post your questions here

Post » Thu Oct 27, 2016 8:23 am

@nimos100 wow, thanks for your initiative, im wondering how make game with 20 cards on screen
i add other card colors but not alwys card matches, sometimes i have last card with no pair
B
24
S
7
Posts: 208
Reputation: 2,032

Post » Thu Oct 27, 2016 8:44 am

IGDev wrote:@nimos100 wow, thanks for your initiative, im wondering how make game with 20 cards on screen
i add other card colors but not alwys card matches, sometimes i have last card with no pair


After you have added the extra 5 cards, you go to Event 7: For "Y" 0 to 1 and you change that to For "Y" 0 to 3

Remember the index starts at 0. So For "X" 0 to 4" = 5 which are the number of cards in the X (Horizontal) direction. So to get 20 cards, we need to have 4 rows in Y (Vertical) direction, because 5 * 4 = 20 :), therefore you need it to be 0 to 3, because that's 4.
B
44
S
11
G
2
Posts: 1,182
Reputation: 6,828

Post » Thu Oct 27, 2016 2:48 pm

@nimos100 yes i set new row for more cards and that thing happen
B
24
S
7
Posts: 208
Reputation: 2,032

Post » Thu Oct 27, 2016 4:03 pm

IGDev wrote:@nimos100 yes i set new row for more cards and that thing happen


My guess is that you have added to many cards, because it should work.

After you run the game and all the cards are on the layout, are the list empty? if it ain't its because you added more cards than you need.
B
44
S
11
G
2
Posts: 1,182
Reputation: 6,828

Post » Thu Oct 27, 2016 9:26 pm

When i create this 3 levels with 6, 10 and 20 cards and when create last 10 pairs how level 1 and 2 will be working if game dont should have too many cards?
nimos100 wrote:
IGDev wrote:@nimos100 yes i set new row for more cards and that thing happen


My guess is that you have added to many cards, because it should work.

After you run the game and all the cards are on the layout, are the list empty? if it ain't its because you added more cards than you need.
B
24
S
7
Posts: 208
Reputation: 2,032

Post » Sat Oct 29, 2016 11:17 am

IGDev wrote:When i create this 3 levels with 6, 10 and 20 cards and when create last 10 pairs how level 1 and 2 will be working if game dont should have too many cards?


My example simply shows how you can make it fairly simple using a fixed amount of cards. If you need more cards or more flexibility you will have to adjust the code for that. Its only meant as a starting point or to give you some ideas.

If you need different amount of cards for each level you have to change the code so it can do that. Because you are right the current code doesn't work if the amount of cards changes. The reason for that is:

Image

Event 4: Here we add all cards in the card object to the list 2 times. So we can assign them to the cards that we place on the table in Event 6 and 7.

Event 6-7: But here is the problem as we create the cards we also assign them a random card from the list. But if we only need 10 cards to be on the table but have added 50 different cards to the list for it to choose from. The chance is that we will end up with none matching cards.

So to fix it, we have to be sure that only the needed amount of cards are available in the list and that we don't add more cards to the table than we have cards for.

To make it easier to work with I add a function that will handle that for us.

Image

Its always a good idea, I think whenever you create a function to write with comment what the function need to work.
So at the top you can see, it requires:

"Needed cards" - This is the total number of cards needed. So 10 for instant means we have 5 cards with 2 of each type, so they match.
"Cards_in_X" - How many cards should be in the horizontal direction. So 5 means you will have 5 cards in a line.
"Cards_in_Y" - How many cards in the vertical direction, so we could make that 2 so you would have 5 cards in each line and 2 rows. Which equal 10 cards.

Event 18: Since we added all cards in our game to the list in Event 4. We might have to many cards in the list for what we actually need. So the first thing we need to do, is to make sure that we only have the correct amount of cards to choose from. So we check whether the "Itemcount" in the list is greater than what we need. If that's the case we need to remove some cards from it. So we choose a random card from the list and store it in the variable "Card_to_remove". The reason to do this is because we added cards twice, so we also need to remove two entries from the list.

Event 19: And we do that here by going through the list and remove all the cards from it which match this "Card_to_remove".

I have a total of 10 different cards in the game. So if I use all of them, the list would look like this:
Image

Imagine that I only wanted to use 6, then the list could look like this:
Image

So now we can remove cards from the list and only end up with the ones we need.

Event 20 - 21: These are the same as in the original, except that we use the "Cards_in_X" and "Cards_in_Y" to decide how we want the cards to be arranged.

So we use the parameters (1) and (2) which we use when calling the functions in the loops to decide that. The reason I subtract one, is simply to avoid having to think about the 0 index in C2, when calling the function.

Image

Event 6: Now that the function is made we don't really have to think about it anymore, all we have to do is to make sure that we call it with the correct values. In this case we want 10 cards, 5 in each line and 2 rows.

So as long as you don't go higher than what you have cards for in the game and you make sure that when calling the function this is true:

[Needed cards = Cards_in_X * Cards_in_Y]

Then it will work.

CAPX - https://dl.dropboxusercontent.com/u/109921357/Simple_match%20game%20tut%20files/Simple_match_game.capx
B
44
S
11
G
2
Posts: 1,182
Reputation: 6,828

Post » Wed Nov 02, 2016 10:23 pm

@nimos100 thanks, im start making game with your example, its possible to put 20 cards like this?
https://www.dropbox.com/s/ikvyx0tw30zgt ... 4.png?dl=0
B
24
S
7
Posts: 208
Reputation: 2,032

Post » Wed Nov 02, 2016 10:56 pm

I guess....

6.......................Function....Call "Generate cards on table"(20,5,4)
Image
B
64
S
23
G
7
Posts: 1,482
Reputation: 10,825

Post » Thu Nov 03, 2016 6:20 pm

@korbaach You have absolutley right :)
@nimos100 You make great work,
B
24
S
7
Posts: 208
Reputation: 2,032

Post » Sun Dec 18, 2016 11:36 am

Help me please.., how to build game like anagram quiz ?
B
9
S
3
Posts: 2
Reputation: 629

Previous

Return to Beginner's Questions

Who is online

Users browsing this forum: Zamargo and 2 guests