# Random Postions

Get help using Construct 2

### » Tue Feb 14, 2012 9:39 am

How do I get random positions to make a slot machine?

I've looked at examples but I still don't understand how it works...
B
5
S
1
G
1
Posts: 111
Reputation: 1,122

### » Tue Feb 14, 2012 10:44 am

If you want a integer number, variableA = int(random(first number,last number));

Do the animation for each number, make them animate when his number is selected for that slot and you will achieve what you need.

>When variableA = 3 on slot 3, play animation of diamond.
B
110
S
24
G
18
Posts: 1,391
Reputation: 22,997

### » Tue Feb 14, 2012 10:54 am

@telle0808

That makes no sense to me?... I don't understand code, I have a single image with 5 different fruit and the 6th is the same as the first fruit. I want it to spin and stop on a random fruit each time. (No Animation)
B
5
S
1
G
1
Posts: 111
Reputation: 1,122

### » Tue Feb 14, 2012 11:07 am

Do you have any .capx?
B
110
S
24
G
18
Posts: 1,391
Reputation: 22,997

### » Tue Feb 14, 2012 11:18 am

.capx

I have spin part but its going the wrong way so I need to change that aswell.
B
5
S
1
G
1
Posts: 111
Reputation: 1,122

### » Tue Feb 14, 2012 11:33 am

Try dividing the height of the sprite, by how many different tiles you have.
If your image was 4 pixels high you could say sprite set y to y+(-4+random(4))
B
178
S
50
G
206
Posts: 8,684
Reputation: 127,711

### » Tue Feb 14, 2012 11:46 am

@newt

I'm not one for maths, the height is 6144 so I assume this is correct:

sprite.Y+(-1024+random(6))

I have 5 different fruit and a 6th which is the first fruit for the loop.
B
5
S
1
G
1
Posts: 111
Reputation: 1,122

### » Tue Feb 14, 2012 12:09 pm

More like .y+((-6(random(6))*1024)
.y+(random(-6,6)*1025) will work as well.
If the return from the random was 1 then 1024 * 1= 1024, if it was 2 it would be 2048, or the second tile.
Keep in mind the negative is there for relative placement, like if the image was already placed at the third tile place.
B
178
S
50
G
206
Posts: 8,684
Reputation: 127,711

### » Tue Feb 14, 2012 12:20 pm

If its not to much trouble could you implement it into my .capx file above?

Cant seem to get it to work, Id like it to stop aswell and then on-click start rotation again.
B
5
S
1
G
1
Posts: 111
Reputation: 1,122

### » Tue Feb 14, 2012 12:38 pm

http://dl.dropbox.com/u/47035927/temp/samples/slot-machine-03.capx
B
110
S
24
G
18
Posts: 1,391
Reputation: 22,997

Next