Scirra Forums

How do I write a function to do something 50% of the time?

How do I write a function to do something 50% of the time?

Posted: Tue Nov 04, 2014 3:37 am

by winkr7

Hello;

I have a bullet that when destroyed creates either explosionOne or explosionTwo 50% of the time. I wrote a function event BulletExplodes that just creates explosionOne and it works fine. How do I write an IF(random(10)<5) type branch to do either explosionOne or explosionTwo. I don't see any way to do an if type statement inside a function.

Thanks for your time.

Re: How do I write a function to do something 50% of the tim

Posted: Tue Nov 04, 2014 3:40 am

by blackhornet

System:Compare two values

Re: How do I write a function to do something 50% of the tim

Posted: Tue Nov 04, 2014 5:00 am

by winkr7

Is this the kind of thing you mean? I can't use Else here for the other explosion.

Thanks for your help.

Re: How do I write a function to do something 50% of the tim

Posted: Tue Nov 04, 2014 5:49 am

by blackhornet

You've got Else at the wrong level. Click on event 16 between the minus sign and the cog - that selects the whole event, then press X. That will give you an Else for that event.

Re: How do I write a function to do something 50% of the tim

Posted: Tue Nov 04, 2014 11:11 pm

by winkr7

I appreciate the help--so I moved up the else but it still won't accept it.