YesNoOk
avatar

ifelse with 3 or more conditionals? (Read 4299 times)

Started by supercain, September 29, 2020, 10:42:24 pm
Share this topic:
ifelse with 3 or more conditionals?
#1  September 29, 2020, 10:42:24 pm
  • avatar
  • **
    • Germany
Hi,

In programming you usually have an option to establish different results for each given conditions but what about mugen? Ifelse only allows 2. Is there a way out there to have 3 or more conditionals? I need something like this for a trigger:

Code:
if partner,stateno = stateno -> SET THIS TRIGGER
if enemy(0),stateno = stateno -> SET THIS OTHER TRIGGER
if enemy(1),stateno = stateno -> THEN SET THIS ONE

How can  I set a trigger like this?

Thank you.
Re: ifelse with 3 or more conditionals?
#2  September 29, 2020, 11:53:58 pm
  • avatar
  • **
    • USA
You can stack ifelse inside another ifelse.  You can actually make a gigantic, functional mess if you want.  I found this delightfully disgusting trigger in CVS2 Urien's CMD file.

Code:
trigger1 = ifelse(ifelse(teamside=2,-1,1)=facing,Abs(enemynear,Pos X-helper(6800),Pos X),Abs(enemynear,Pos X-helper(6850),Pos X))<=140

I'm not even sure what to make of that.  But yeah, an ifelse can be a condition.
Re: ifelse with 3 or more conditionals?
#3  September 30, 2020, 01:17:51 am
  • ****
    • crepa.neocities.org
clean example using a variable that is either 1, 2 or 3

ifelse(var(10) = 1, 1000, ifelse(var (10) = 2, 2000, 3000))

yes, the last one is omitted, is assumed that if var(10) is not 1 or 2, it will be 3 no matter what, you can also use a triggerall to ensure it, like this:

triggerall = (var(10) = [1,3])
Re: ifelse with 3 or more conditionals?
#4  September 30, 2020, 01:45:13 am
  • avatar
  • **
    • Germany
Thanks. I had tried that in the past but Im not sure if it works as desired. Does it?
Re: ifelse with 3 or more conditionals?
#5  September 30, 2020, 01:48:42 am
  • ****
    • crepa.neocities.org
Uh... if we're recommending it... it should work, right?
Re: ifelse with 3 or more conditionals?
#6  September 30, 2020, 02:18:57 am
  • avatar
  • **
    • USA
After thinking this over, unless you've overgeneralized your example, you don't even need ifelse.  Every trigger in a state is an "if" on its own and the "else" is automatically do nothing.  Just use three different states.

Why cram it into one function?  Something like this.

Code:
[statedef -2]

[state 0, whatever]
type=varset
trigger1 = partner,stateno = stateno
v = 997
value = lol

[state 0, whatever]
type=varset
trigger1 = enemy(0),stateno = stateno
v = 998
value = lol

[state 0, whatever]
type=varset
trigger1 = enemy(1),stateno = stateno
v = 999
value = lol
Re: ifelse with 3 or more conditionals?
#7  September 30, 2020, 02:46:27 am
  • ****
    • USA
    • twitter.com/inktrebuchet
similar to the last post.
Code:
[state n]
type = null
trigger1 = numpartner
trigger1 = partner,stateno = stateno
trigger1 = var(0) := 1
;--------
trigger2 = numenemy(0)
trigger2 = enemy(0),stateno = stateno
trigger2 = var(1) := 1
;-------
trigger3 = numenemy(1)
trigger3 = enemy(1),stateno = stateno
trigger3 = var(2) := 1

From how you've described it, an actual ifelse isn't needed. Normally ifelse or cond is used as "if, then, else" arguments.
Re: ifelse with 3 or more conditionals?
#8  September 30, 2020, 08:58:22 pm
  • avatar
  • **
    • Germany
Im intrigued, what does the
Code:
:=

mean?
Re: ifelse with 3 or more conditionals?
#9  September 30, 2020, 09:30:16 pm
  • *
    • Mexico
    • Reptorebanador@gmail.com
":=" basically means "becomes" so in using taht trigger your variable is becomming the value there, so for example var(1) := 1 will make var(1) = 1
Re: ifelse with 3 or more conditionals?
#10  October 02, 2020, 01:46:29 am
  • avatar
  • **
    • Germany
Hmm, so for example:

Code:
[state n]
type = changestate
trigger1 = var(1) := 1
value = 30

means that the player will change to state no. 30 when variable equals 1?

Re: ifelse with 3 or more conditionals?
#11  October 03, 2020, 10:06:28 pm
  • ******
  • Legendary XIII
  • I am the eye of the storm to come!
    • New Zealand
    • network.mugenguild.com/cyanide/
No. That would simply set var 1 to 1 and eithef trigger constantly or never trigger at all. The := operator isn't used to make something activate but to set a value inline with other code.

Many peoplle use it as alternative to multtiple varset sctrls. You can just do a null state and set up 10 lines for varset rather than 10 varsets.


In M.U.G.E.N there is no magic button

They say a little knowledge is a dangerous thing, but it's not one half so bad as a lot of ignorance.