How do you make a random event?( capx needed )

0 favourites
From the Asset Store
Easily generate many levels from a set of pre-built scenes (Construct 3 template)
  • How do you make an action based on random? I know about the random expression but i don't know how to use it. I don't want you to explain it. You should make a capx whit an enemy that can do four things. Shoot up, shoot to the rigth and shoot to the left and shoot down. The enemy should have a 25 % of doing onw of those four things every four seconds. The enemy should be completly coulored green and nothing else and the shots the same. Then share it whit a link in some way. I have asked this question before but now i ask it whit more clearity.

  • every 4.0 seconds

    for each enemy

    --- create bullet at (enemy.x, enemy.y)

    --- bullet: set angle to 90*int(random(4))

  • How do you make an action based on random? I know about the random expression but i don't know how to use it. I don't want you to explain it. You should make a capx whit an enemy that can do four things. Shoot up, shoot to the rigth and shoot to the left and shoot down. The enemy should have a 25 % of doing onw of those four things every four seconds. The enemy should be completly coulored green and nothing else and the shots the same. Then share it whit a link in some way. I have asked this question before but now i ask it whit more clearity.

    Demanding someone creates a .capx with exactly what you want is not the right way of asking for assistance.

  • While R0J0's answer is correct, I thought I'd take a moment to explain why this works.

    random(x) returns a random number between 0 and x, Including random decimal points. So therefore random(4) could return 0, or 1.75 or 3.14 or 1.1217597243 or whatever, as long as it's a positive number and below (but not including) 4.

    This is where the int() comes in. By using the int() expression he converts the number to one that does not have fractions, it's effectively the same as using floor(). 1.75 would become 1, 3.14 would become 3, and there are now only 4 possible numbers that int(random(4)) can produce: 0, 1, 2 or 3 (each with an equal chance).

    Now by taking this and multiplying it by 90, your possible angles for the bullet are 0, 90, 180 and 270, which does exactly as you wanted it to.

  • While R0J0's answer is correct, I thought I'd take a moment to explain why this works.

    random(x) returns a random number between 0 and x, Including random decimal points. So therefore random(4) could return 0, or 1.75 or 3.14 or 1.1217597243 or whatever, as long as it's a positive number and below (but not including) 4.

    This is where the int() comes in. By using the int() expression he converts the number to one that does not have fractions, it's effectively the same as using floor(). 1.75 would become 1, 3.14 would become 3, and there are now only 4 possible numbers that int(random(4)) can produce: 0, 1, 2 or 3 (each with an equal chance).

    Now by taking this and multiplying it by 90, your possible angles for the bullet are 0, 90, 180 and 270, which does exactly as you wanted it to.

    What's the difference between using floor() and int()?

  • floor takes a number and rounds it down to the nearest whole number.

    int converts a variable/number into an integer (which by definition, does not have decimal places, aka a whole number).

    So basically floor(3.14) gives a real number which is 3.00

    While int(3.14) gives an integer which is 3

  • every 4.0 seconds

    for each enemy

    --- create bullet at (enemy.x, enemy.y)

    --- bullet: set angle to 90*int(random(4))

    That information was helpful and now i know how to make a enemy shoot in random directions. But i still want to know how to make enemys spawn in random image points of a sprite and how to make enemy switch to random animations. I tried usiing the same solution as for shooting in random directions but it does not work.

  • You could also use choose instead of random:

    For animations

    sprite set animation to : choose("animation1","animation2") etcetera

    For spawning at imagepoints

    sprite spawn object on layer at imagepoint choose(0,1,2,3,4,5)

  • You could also use choose instead of random:

    For animations

    > sprite set animation to : choose("animation1","animation2") etcetera

    For spawning at imagepoints

    > sprite spawn object on layer at imagepoint choose(0,1,2,3,4,5)

    When i try to make a sprite switch to random animations i write in the words exactly like you did and i keep getting the error message "expression seem to end before here. are you missing something before it. Other then that the information was very helpful.

  • > You could also use choose instead of random:

    >

    > For animations

    >

    > > sprite set animation to : choose("animation1","animation2") etcetera

    >

    > For spawning at imagepoints

    >

    > > sprite spawn object on layer at imagepoint choose(0,1,2,3,4,5)

    >

    When i try to make a sprite switch to random animations i write in the words exactly like you did and i keep getting the error message "expression seem to end before here. are you missing something before it. Other then that the information was very helpful.

    You didn't write etcetera, did you?

  • >

    > > You could also use choose instead of random:

    > >

    > > For animations

    > >

    > > > sprite set animation to : choose("animation1","animation2") etcetera

    > >

    > > For spawning at imagepoints

    > >

    > > > sprite spawn object on layer at imagepoint choose(0,1,2,3,4,5)

    > >

    >

    > When i try to make a sprite switch to random animations i write in the words exactly like you did and i keep getting the error message "expression seem to end before here. are you missing something before it. Other then that the information was very helpful.

    >

    You didn't write etcetera, did you?

    I did now and it still says Syntax error Expression appears to end before here-are you missing something before it? What should i change in the expression?

    http://postimg.org/image/jywfrk74d/

  • When i try to make a sprite switch to random animations i write in the words exactly like you did and i keep getting the error message "expression seem to end before here. are you missing something before it. Other then that the information was very helpful.

    You didn't write etcetera, did you?

    I did now and it still says Syntax error Expression appears to end before here-are you missing something before it? What should i change in the expression?

    http://postimg.org/image/jywfrk74d/

    An answer please? I posted a image so it should be clear what you should help me whit.

  • Throw away everything after the closing bracket. just: choose(...)

  • Like this?

    http://postimg.org/image/qn6b6fwz7/

    In that case it still doesn't work. Just how am i supposed to write it?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Like this?

    http://postimg.org/image/qn6b6fwz7/

    In that case it still doesn't work. Just how am i supposed to write it?

    The Choose Expression gives you the correct syntax, which you already had except for the last bit after the closing bracket, as blackhornet had already told you, which was to only remove the

    ""etcetera
    [/code:2pdmsvi0]
    
    nonsense from the end.
Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)