How to add randomness in Construct 2?

0 favourites
From the Asset Store
Casino? money? who knows? but the target is the same!
  • 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 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..

  • 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 %.

  • 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?

  • 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 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..

  • > 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.

  • 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.

  • 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.

  • > 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..

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 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.

  • >

    > > 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..

    What i got out from the manual was how you could make something spawn at random locations sine it showed a event from that. So i got help whit that. But i also want to know hoe to make a enemy do a movement or spawn something at random I still want to know two things about that.I used the Timer behavior like this. On start of layout Start Timer1 for 1.0 (Regular). On Compare values i have written "(random)" as a frst value and "(triggerchance)" as the second value. I need paranthesis. It doesn't work for me otherwise. If i just write (random) the expression complains on the lack of paranthesis. Then i made the compare values happen on time. This makes the sprite do the event exactly every second instead of at random like it should so the way i made the timer didn't work. How do you make a expression whitout a variable? You said i shouldn't have a variable for the random expression. Should i go into system, the sprite or what? Second i still want to know if i should make a single event whit random expression or just compare two values or both. If i should both, should the random event happen after the random expression or after the value comparing? I hope i am clear whit what i am asking.

  • 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..

    What i got out from the manual was how you could make something spawn at random locations sine it showed a event from that. So i got help whit that. But i also want to know hoe to make a enemy do a movement or spawn something at random I still want to know two things about that.I used the Timer behavior like this. On start of layout Start Timer1 for 1.0 (Regular). On Compare values i have written "(random)" as a frst value and "(triggerchance)" as the second value. I need paranthesis. It doesn't work for me otherwise. If i just write (random) the expression complains on the lack of paranthesis. Then i made the compare values happen on time. This makes the sprite do the event exactly every second instead of at random like it should so the way i made the timer didn't work. How do you make a expression whitout a variable? You said i shouldn't have a variable for the random expression. Should i go into system, the sprite or what? Second i still want to know if i should make a single event whit random expression or just compare two values or both. If i should both, should the random event happen after the random expression or after the value comparing? I hope i am clear whit what i am asking.

    Can anyone answer on this question. Please?

  • Without seeing your capx and/or eventsheet it is very unclear what you want..

    If you are comparing if "(random)" is the same as "(triggerchance)" it will never be true, for the string (random) and the string (triggerchance) are not the same..

    What I'm trying to say is that instead of values you are comparing strings (texts), which doesn't seem to be what you want..

    What your event-sheet should look like if you are following the example provided on the last page:

    ("Is equal to" should offcourse be replaced by "less or equal")

  • Without seeing your capx and/or eventsheet it is very unclear what you want..

    If you are comparing if "(random)" is the same as "(triggerchance)" it will never be true, for the string (random) and the string (triggerchance) are not the same..

    What I'm trying to say is that instead of values you are comparing strings (texts), which doesn't seem to be what you want..

    What your event-sheet should look like if you are following the example provided on the last page:

    ("Is equal to" should offcourse be replaced by "less or equal")

    I wrote it like this and the enemy doesn't do anything.

    http://postimg.org/image/8mra79th7/

    I don't know how you compare a text. Should i make a text? Even if i make a text it still needs a instance variable to compare. So i made a instance variable triggerchance and set in the number 30. Does that also work?

  • Why do you want to compare text?

    when you use the " " around something it's a text/string..

    Why not make it like the way I showed?

    There is no need for the sprite71 within the comparison, I'm not sure what you expect it to do there, but this sure isn't the way..

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)