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.

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()?

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.

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

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

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

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?

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.