# How to add randomness in Construct 2?

Get help using Construct 2

### » Wed Sep 16, 2015 9:27 am

I have found two choosable instances whit randomness in Construct 2. The first being the random offset on the Sine behavior. The second being Pick random instance. But i can't use these to make the randomness i want. I simply want to know how to make a event happen at random whitout anything triggering it. I also want to know how i affect the chance in % of the random event happening.
B
12
S
2
Posts: 267
Reputation: 1,344

### » Wed Sep 16, 2015 11:41 am

I guess using random() in your expressions would be a good start for randomness..
Also choose() could work..

An event won't happen without ANYTHING triggering it though, it only happens when conditions are met..
Adding the random() or choose() inside the expressions of those conditions should do the trick..
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

### » Wed Sep 16, 2015 11:49 am

triggerChance = 30 (this is some variable)

System-> Compare two values (floor(random(101)) <= triggerChance) -> (do whatever you need)

In this example you have 30% to trigger actions under this condition. By manipulatin "triggerChance" you can affect the chance in %.
B
38
S
22
G
89
Posts: 1,086
Reputation: 50,298

### » Wed Sep 16, 2015 3:00 pm

BackendFreak wrote:triggerChance = 30 (this is some variable)

System-> Compare two values (floor(random(101)) <= triggerChance) -> (do whatever you need)

In this example you have 30% to trigger actions under this condition. By manipulatin "triggerChance" you can affect the chance in %.

I am going to reply to both answers. I was suprised by it existing a choosable expression called random. I thaugth no thing existed. That's a interesting thing about Construct 2. You doesn't seem to have that many options at first glance but you really have if you look into it. I was sucessfull in creating a random expression but i got into problems on the trigger chance part. I name my random instance variable random and set it to number and make the number 101. The second variable is called triggerchance and is also a number whit the number 30. Is that rigth or not? Then whit compare two values. On the first value i try to write it like you did it. Is floor the eqvivaluent of the sprite the random event is going to happen whit? So should i first write in the sprites name, then the number and the random expression? I try to do it like you wrote but it doesn't work. Do you need such a complex text on the first value. Can i just not just write down the name of the values?
B
12
S
2
Posts: 267
Reputation: 1,344

### » Wed Sep 16, 2015 3:07 pm

Floor(random(101)) will supply a random integer number between 0 and 100

Floor is used to round the number down, so only integer values will be used and not floats..

You only need 1 variable in the example @BackendFreak showed (It could even be done without a variable)
Triggerchance will determine the percentage. from the possible 100 numbers Floor(random(101)) will supply only 30 are below or equal to Triggerchance if it's set to 30
30 from a hundred is 30%

so to clarify random is an expression, you don't need a variable for it..
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

### » Wed Sep 16, 2015 3:16 pm

Calfuso wrote:
BackendFreak wrote:triggerChance = 30 (this is some variable)

System-> Compare two values (floor(random(101)) <= triggerChance) -> (do whatever you need)

In this example you have 30% to trigger actions under this condition. By manipulatin "triggerChance" you can affect the chance in %.

I am going to reply to both answers. I was suprised by it existing a choosable expression called random. I thaugth no thing existed. That's a interesting thing about Construct 2. You doesn't seem to have that many options at first glance but you really have if you look into it. I was sucessfull in creating a random expression but i got into problems on the trigger chance part. I name my random instance variable random and set it to number and make the number 101. The second variable is called triggerchance and is also a number whit the number 30. Is that rigth or not? Then whit compare two values. On the first value i try to write it like you did it. Is floor the eqvivaluent of the sprite the random event is going to happen whit? So should i first write in the sprites name, then the number and the random expression? I try to do it like you wrote but it doesn't work. Do you need such a complex text on the first value. Can i just not just write down the name of the values?

'

I just wrote in "(random)" as a first value and "(triggerchance)" and less then and it worked. The question is, should i make the event after the compare two values thing or should the compare two values thing be a seperate event. Becuase i made the event afterwards and it happened all the time instead of at random. I choosed less then, is that wrong? Should i make the random expression and then the random event and the compare two values as a seperate event. Was my naming of the values wrong. I know i am talking very advanced know and you may not understand what i mean.
B
12
S
2
Posts: 267
Reputation: 1,344

### » Wed Sep 16, 2015 3:27 pm

First of all you don't need parenthesis. You use them to group calculations like in math.

Second thing. Every event is being checked every frame (so approx. 60 times a second). So if you want to trigger this random calculation only once then you have to add an extra check which will determine if this should be ran or not (suggesting a boolean-like variable or a trigger action like "On tap..."). But I have a feeling that the first thing you should read is How Events Work. Then you may want to read about the "hidden" useful functions called System expressions. This should make many things clear for you.
B
38
S
22
G
89
Posts: 1,086
Reputation: 50,298

### » Wed Sep 16, 2015 4:09 pm

BackendFreak wrote:First of all you don't need parenthesis. You use them to group calculations like in math.

Second thing. Every event is being checked every frame (so approx. 60 times a second). So if you want to trigger this random calculation only once then you have to add an extra check which will determine if this should be ran or not (suggesting a boolean-like variable or a trigger action like "On tap..."). But I have a feeling that the first thing you should read is How Events Work. Then you may want to read about the "hidden" useful functions called System expressions. This should make many things clear for you.

The Manual has never or will never help me. It's something whit how it's written whit not including all the fact you need and being confusing. If i couldn't understand the manual better i would ask alot less in these forums. I like tutorials though. I want to try the Boolean thing. I made a Boolean and set it to false. Shall i set it to true after the event has happened or what.
B
12
S
2
Posts: 267
Reputation: 1,344

### » Wed Sep 16, 2015 4:26 pm

Calfuso wrote:
BackendFreak wrote:First of all you don't need parenthesis. You use them to group calculations like in math.

Second thing. Every event is being checked every frame (so approx. 60 times a second). So if you want to trigger this random calculation only once then you have to add an extra check which will determine if this should be ran or not (suggesting a boolean-like variable or a trigger action like "On tap..."). But I have a feeling that the first thing you should read is How Events Work. Then you may want to read about the "hidden" useful functions called System expressions. This should make many things clear for you.

The Manual has never or will never help me. It's something whit how it's written whit not including all the fact you need and being confusing. If i couldn't understand the manual better i would ask alot less in these forums. I like tutorials though. I want to try the Boolean thing. I made a Boolean and set it to false. Shall i set it to true after the event has happened or what.

Why not?
You could even add the timer behaviour so it will only be triggered on timer and set the timer to a random number as well..
Change the boolean on timer could also work..

So many ways to do one thing, that might be what's confusing you about the manual, it doesn't tell you what to do, only what you can do..
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

### » Wed Sep 16, 2015 4:42 pm

Calfuso wrote:I have found two choosable instances whit randomness in Construct 2. The first being the random offset on the Sine behavior. The second being Pick random instance. But i can't use these to make the randomness i want. I simply want to know how to make a event happen at random whitout anything triggering it. I also want to know how i affect the chance in % of the random event happening.

I know that i write tons of replies over another and another but i am replying as i am testing. I want to know if i need to make a random expression and a value comparing. or just a value comparing. And which should trigger the event? I have made it so the value comparing only happens every 3.0 second. That makes the event happen exactly every 3.0 second. It should happen at a third of the time every 3.0 second. The timer behavior is also something i have trouble whit. I am going to try now and i hope it works but it may not. Geez this is going to take forever. Thank you if you are persistent enough to keep on helping me make me in the end solve this.
B
12
S
2
Posts: 267
Reputation: 1,344

Next