YesNoOk
avatar

if else random help. (Read 1290 times)

Started by Momotaro, August 10, 2020, 02:07:32 pm
Share this topic:
if else random help.
#1  August 10, 2020, 02:07:32 pm
  • *****
  • A.K.A. NED
  • I like to draw fighting game characters...
I'm tryning to code a random voice selection for win pose.

Something like 50% of chance of each of the to voice to occur.

I tried for several minutes, but even with the docs, I cannot completed it effectively.
sounds are :
181,0
181,1

I know the structure is bad...

What I started.
Code:
;;;;random number between 0 and 999, inclusive.
[State 181, Voice]
type = PlaySnd
Triggerall = ifelse(random, <=499, <499)

trigger1 = !Time
value = 181,0
channel = 0


Any help is welcome.
Last Edit: August 10, 2020, 05:11:29 pm by Nedflandeurse
Re: if else random help.
#2  August 10, 2020, 03:23:30 pm
  • ******
  • Hedgehog Whisperer
  • Red Bull addict
    • Spain
    • xgargoyle.mgbr.net

  • Online
[State 181, Voice]
type = PlaySnd
trigger1 = !Time
value = 181,random%2
channel = 0
XGargoyle: Battle posing since 1979
http://xgargoyle.mgbr.net
http://www.pandorabots.com/pandora/talk?botid=e71c0d43fe35093a  <-- Please click that link
http://paypal.me/XGargoyle  <-- Donations welcome!
Re: if else random help.
#3  August 10, 2020, 05:11:05 pm
  • *****
  • A.K.A. NED
  • I like to draw fighting game characters...
Re: if else random help.
#4  August 10, 2020, 07:30:09 pm
  • ****
    • crepa.neocities.org
So, I feel like adding some more information for future reference.
First, I don't quite understand what you did there. The right thing would be:

[State 181, Voice]
type = PlaySnd
trigger1 = !Time
value = 181,ifelse(random < 500, 0, 1); if random is less than 500, sound will be 0, if not, will be 1
channel = 0

XG's method also works the same, "random%x", in resume, will generate a number starting from 0, up to the number you replace x with, in this case is %2, so between 0 and 1.

Second, random generates a number between 0 and 999 every tick, yes, but EACH and EVERY random are different numbers, even in the same block of code.
Let's suppose you want a 33% chance of something happening, you will NOT use this:

trigger1 = random >=333 && random < 666

the 2 randoms here will not be the same number. They act individually. For a 33% chance, I'd do this:

trigger1 = random < 333

or, if I need to choose between 3 different numbers:

trigger1 = ifelse(random < 333, 0, ifelse(random < 500, 1, 2))

I hope it makes sense to you.
Re: if else random help.
#5  August 10, 2020, 07:43:53 pm
  • *****
  • A.K.A. NED
  • I like to draw fighting game characters...
This is many many information.
But I think I got the idea.

thanks friend, for taking the time to explain how it can be done !