ID:155075
 
I was wondering if anyone knows a way to have a procedure happen exactly 50% of the time. I'm not taking about using prob(50) or pick(A,B) or whatever.

For example I'd like a projectile to move 2 steps, then create another object. Any ideas?
Modulus!

for(var/n in 1 to 10)
if(!(n % 2))
world << n
In response to Kaiochao
Kaiochao wrote:
Modulus!

> for(var/n in 1 to 10)
> if(!(n % 2))
> world << n

Ah thank you, do you possibly think you could go into a bit of detail how this works? I'd like to use this for future reference as well
In response to AbdelJN
Check the DM Reference entry for the % operator. It simply gives the remainder of A divided by B.

In the example I provided, it checks if A%B is 0, which is the case in even numbers divided by 2.
In response to Kaiochao
Kaiochao wrote:
Check the DM Reference entry for the % operator. It simply gives the remainder of A divided by B.

In the example I provided, it checks if A%B is 0, which is the case in even numbers divided by 2.

Alright but not all even numbers divided by 2 equals 0 so the example doesn't really work unless I'm missing something.
In response to AbdelJN
Name a single even number that, divided by 2, leaves a remainder that is not 0.
In response to Robertbanks2
Robertbanks2 wrote:
Name a single even number that, divided by 2, leaves a remainder that is not 0.

Sorry, I misunderstood. I saw the % operator as solely giving the quotient of two numbers. Then I read again and found that it gives the remainder.

As for your example Kaiochao, it's correct. Thanks:)