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?
ID:155075
Sep 26 2011, 2:51 pm
|
|
Kaiochao wrote:
Modulus! 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 | |
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. | |
Kaiochao wrote:
Check the DM Reference entry for the % operator. It simply gives the remainder of A divided by B. Alright but not all even numbers divided by 2 equals 0 so the example doesn't really work unless I'm missing something. | |
Name a single even number that, divided by 2, leaves a remainder that is not 0.
| |
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:) | |
<dm>
for(var/n in 1 to 10)
if(!(n % 2))
world << n