6 Sprite in 6 random positions

Get help using Construct 2

Post » Wed Oct 26, 2011 9:10 pm



Hello,

I have 1 newbie question:

There are 6 positions and 6 different colors cards.
I want every time when launch the game each card to be placed in different position (random).

And how then i can get which card which position is?
Using variable or?
B
9
S
1
G
2
Posts: 10
Reputation: 2,245

Post » Wed Oct 26, 2011 9:21 pm

Make the empty grid an array. On start of layout, fill the array with numbers 1 - 6 in a random order (not sure how do do this off the top of my head.)

If you are not familiar with arrays, there is a nice tutorial for it in the tutorials section (you will need to be familiar with loops to fill the array).

Now, it is easy to get which card is at which position. use the command array.at(x,y).

A rule of thumb to help you: when you have a grid, more often than not you will want an array.sqiddster2011-10-26 21:22:17
B
90
S
30
G
24
Posts: 3,189
Reputation: 32,400

Post » Fri Oct 28, 2011 4:00 pm

OK , I did this:

Online Demo:

http://dl.dropbox.com/u/47308347/Cards_Demo_01/index.html

But i have 2 Questions:

1. How i can make 10 random generated numbers from 1 to 10
without [Plugin] RandomArray?
http://www.scirra.com/forum/plugin-randomarray_topic45277.html
Example: 7,8,5,9,1,3,10,2,4,6.

2. How i can optimize my code? Now is 100+ code lines for 10 random
cards... this is insane.

My CAPX file:
http://dl.dropbox.com/u/47308347/Cards_Project/cards01.capx
(You need [Plugin] RandomArray to start file!)theone862011-10-28 18:19:25
B
9
S
1
G
2
Posts: 10
Reputation: 2,245

Post » Fri Oct 28, 2011 7:43 pm

I wouldn't use a different object type for each card. You should just need two. One for the positions and on with all the different cards as animation frames.

Then it can be done simply with two events:
http://dl.dropbox.com/u/5426011/c2/cards.capx

You can then pick a card at say position 6 with two conditions:
Sprite: instance variable position=4
Pick Card by UID: Sprite.card
B
79
S
24
G
54
Posts: 4,738
Reputation: 40,739

Post » Fri Oct 28, 2011 9:46 pm

Hi,

perhaps this helps
scramble cards

haven't seen, that the solution above is better
Joe72011-10-28 22:05:37
B
14
S
6
G
5
Posts: 173
Reputation: 4,742

Post » Fri Oct 28, 2011 10:35 pm



R0J0hound
How do you always have 2 identical cards by color:
2 red 2 yellow 2 green... which line of code is this?

Can you explain this: loopindex % 5 ?

Joe7
Interesting example.

Thanks for answers!
B
9
S
1
G
2
Posts: 10
Reputation: 2,245

Post » Sat Oct 29, 2011 7:13 pm

The % symbol gives the remainder of a division.
So with loopindex % 5 you get:
0 % 5 => 0
1 % 5 => 1
2 % 5 => 2
3 % 5 => 3
4 % 5 => 4
5 % 5 => 0
6 % 5 => 1
7 % 5 => 2
8 % 5 => 3
9 % 5 => 4

so each frame each animation frame is used twice.
B
79
S
24
G
54
Posts: 4,738
Reputation: 40,739

Post » Sun Dec 04, 2011 9:53 pm

This is my little progress (maybe):

http://dl.dropbox.com/u/47308347/Cards_Demo_02/index.html
(Online Demo)

http://dl.dropbox.com/u/47308347/Cards_Project/cards02.capx
(CAPX File)

Please, tell me - can i optimize my code?
Please, tell me - if you find any "bug"?

P.S. This is my first test game with Construct 2.
I am 100% sure, i miss many things.
B
9
S
1
G
2
Posts: 10
Reputation: 2,245

Post » Sun Dec 04, 2011 11:43 pm

Dude... I can't read your variable name, write your capx in english and put some comments. It's easier if you really want help.
B
60
S
22
G
14
Posts: 1,479
Reputation: 16,346

Post » Fri Feb 28, 2014 11:30 pm

hi
i want to ask something, its simillar to Theone66 question,but my object was text,
there is a text that i clone to 3 different text, the problem with that is , the random text can only 1 text, the other 2 wasn't random

for example i have "bubu", "bibi" , "bobo". but only "bubu" that shown.
Image

this is the result
Image
B
2
Posts: 1
Reputation: 202

Next

Return to How do I....?

Who is online

Users browsing this forum: Google [Bot] and 21 guests