# How do I Jump Random Times To Break A block

Get help using Construct 2

### » Sun Nov 16, 2014 8:45 am

I would like to make the player jump on a block more than once to break it. Right now it breaks if the player jumps once, but how can i create an event that makes the player jump a random amount of times (2 - 4) to break it?

Thank you for any help.
B
38
S
18
G
19
Posts: 664
Reputation: 14,112

### » Sun Nov 16, 2014 8:58 am

You should use instance variables for this. https://www.scirra.com/manual/73/instance-variables
Create an instance variable for the block and set it to 2 or 4. Then when the player collisions with the block, subtract 1 from that variable. And if the variable is less than 1 destroy the block.
B
76
S
29
G
17
Posts: 256
Reputation: 15,275

### » Sun Nov 16, 2014 9:18 am

Thank you for the reply Xavier. Guess i'm finally gonna have to try and wrap my brain around instance variables.
B
38
S
18
G
19
Posts: 664
Reputation: 14,112

### » Mon Nov 17, 2014 9:51 am

Xavier wrote:Create an instance variable for the block and set it to 2 or 4.

Is it possible to add to that instance variable by the system picking a random number between 2 and 4? So it could be 2 hits, or 3, or 4?
B
38
S
18
G
19
Posts: 664
Reputation: 14,112

### » Mon Nov 17, 2014 10:02 am

Yes. You need to use the random() expression, you would use it like this: round(random(2,4))

The round expression will round a number, so if you get 4.2, it will show 4. More on: https://www.scirra.com/tutorials/77/nat ... onstruct-2

You should create an action at layout start to set the instance variable for the blocks to round(random(2,4))
Modify the numbers as you see fit.
B
76
S
29
G
17
Posts: 256
Reputation: 15,275

### » Mon Nov 17, 2014 10:10 am

Thank you once again, Xavier.

I just finished with the instance variable and it worked great, going back over the ghost shooter tutorial and subtracting the health.
B
38
S
18
G
19
Posts: 664
Reputation: 14,112