YesNoOk
avatar

mugen cond trigger (Read 4345 times)

Started by Websta, August 26, 2015, 04:45:58 pm
Share this topic:
mugen cond trigger
#1  August 26, 2015, 04:45:58 pm
  • ****
  • play more SNK games
  • I FUCKING LOVE PLATINUM!
    • South Africa
    • www.trinitymugen.net/
Can somebody please explain to me how it works? I know my life will be easier if I use it, but all my attempts end with either nothing happening or mugen exiting with no error messages.

A detailed explanation with an example will be appreciated as I'm feeling especially dull at the moment.
Re: mugen cond trigger
#2  August 26, 2015, 09:57:30 pm
  • ****
  • Target Acquired.
    • Ukraine
    • mugencoder.com
cond() works similar to ifelse() in that it takes an expression, evaluates it, and then returns the value of the expression in the 2nd or 3rd parameter depending on whether the first expression (parameter #1) is true or false respectively.

These:
Code:
ifelse(life=lifemax, 1.0, 0.5)
cond(life=lifemax, 1.0, 0.5)
are logically equivalent and will return "1.0" as the value if your character is at max life.

The difference is that ifelse() will evaluate all expressions and cond() will not. For example:
Code:
ifelse(numhelper(30), helper(30),pos x, 0)
will actually cause debug flood if helper(30) doesn't exist. Why? Because with ifelse(), numhelper(30), helper(30),pos x, and "0" are all evaluated and then the result is of the final expression is returned. Using the same expressions with cond() will look like this:
Code:
cond(numhelper(30), helper(30),pos x, 0)
This will return the same result without the potential for debug flood. First numhelper(30) is evaluated. If it's true, only then will "helper(30),pos x" be evaluated and its result returned. If "numhelper(30)" is false, ie. "0," then "helper(30),pos x" won't ever be seen.

cond() is most synonymous to a ternary expression in actual programming and scripting languages, such as JavaScript and PHP. ifelse() is just a broken mess. I hope that helps to clear up any confusion you had about it, but I'm curious as to how you're trying to use it that it's crashing mugen.

-[Все слова это только слова.]-
Re: mugen cond trigger
#3  August 27, 2015, 01:07:00 pm
  • ****
  • play more SNK games
  • I FUCKING LOVE PLATINUM!
    • South Africa
    • www.trinitymugen.net/
So there's not much difference between to the two huh..

Thanks for the info though, also I might have forgotten or a comma or something that made that crash happen, I dunnò.
Re: mugen cond trigger
#4  August 27, 2015, 01:09:18 pm
  • **
  • NvP!
so basically its the same code, just that cond isn't that bugged like ifelse ?
Wow i might use cond only now
Re: mugen cond trigger
#5  August 27, 2015, 01:12:17 pm
  • *****
  • Hug Pikachus!
    • USA
Me too. You learn something every day.

Might give me enough motivation to do things now...
Hug the Pikachus!

Hug A Pikachu Today!
Re: mugen cond trigger
#6  August 27, 2015, 03:13:30 pm
  • ****
  • Robotics Engineer
    • USA
    • altoiddealer@gmail.com
Using IfElse, MUGEN will evaluate the entire code - both "true" and "false" statements.

Using Cond, MUGEN will ONLY evaluate one statement.

As far as I can tell, there is no reason to ever use IfElse... Cond works exactly the same, but prevents errors.


MUGEN will report errors if the code it is evaluating is invalid.  Such as, if you use a trigger redirection to a non-existent player.

EXAMPLE:

Code:
IfElse(PlayerIDExist(60),(PlayerID(60),Pos X - 100),ScreenPos X + 100))
If there is not a Player with ID 60, this will result in an error because the "false" code (PlayerID(60),Pos X - 100) is still being evaluated, even though it is not being triggered.

Code:
Cond(PlayerIDExist(60),(PlayerID(60),Pos X - 100),ScreenPos X + 100))
If the condition is "false" (there is not a Player with ID 60), the "true" code is completely ignored and is not evaluated - there will be no error.

Last Edit: August 27, 2015, 03:23:34 pm by altoiddealer
Re: mugen cond trigger
#7  August 27, 2015, 03:48:50 pm
  • ******
    • www.justnopoint.com/
Since I'm rebuilding I'll use this knowledge to replace the coding.
This info should be linked to in one of our stickies as well. I'll get on that.
Re: mugen cond trigger
#8  August 27, 2015, 05:50:50 pm
  • ****
  • Target Acquired.
    • Ukraine
    • mugencoder.com
As far as I can tell, there is no reason to ever use IfElse... Cond works exactly the same, but prevents errors.
True, most people wouldn't use it, but you can technically use it to your advantage in some cases. In knowing that all of your expressions are evaluated, you could make use of shorthand assignments within that/those expression(s), saving you from needing an extra VarSet/VarAdd. It would be extremely specific though.

-[Все слова это только слова.]-
Re: mugen cond trigger
#9  August 27, 2015, 07:25:42 pm
  • ******
  • [E]
    • Mexico
yet it was so non-specific that elecbyte, instead of fixing ifelse, craeted the cond trigger.

So there's not much difference between to the two huh..

Thanks for the info though, also I might have forgotten or a comma or something that made that crash happen, I dunnò.

mugen's parser is very finicky regarding the "," operator, that might be related to your crashes; try adding extra () when you ahve , in your code, extra () tend to make mugen stop crashingon expressions (as the , case is not the only one).
Re: mugen cond trigger
#10  August 27, 2015, 07:32:31 pm
  • ****
  • Robotics Engineer
    • USA
    • altoiddealer@gmail.com
As far as I can tell, there is no reason to ever use IfElse... Cond works exactly the same, but prevents errors.
True, most people wouldn't use it, but you can technically use it to your advantage in some cases. In knowing that all of your expressions are evaluated, you could make use of shorthand assignments within that/those expression(s), saving you from needing an extra VarSet/VarAdd. It would be extremely specific though.


Got an example?

Re: mugen cond trigger
#11  August 27, 2015, 07:51:10 pm
  • ****
  • Target Acquired.
    • Ukraine
    • mugencoder.com
Got an example?

Off the top of my head with no testing whatsoever, you could do something like this:
Code:
var(0) := ifelse( !time, var(1):=1, var(2):=2) 
It sets the value of var(1) and var(2) and readily returns one of them to var(0). Replace the value of those assignments to something more complex and you'd avoid having to revaluate a potentially complex expression for the sake of storing its value. Of course this could be done in other ways, but this does it on one line. Unfortunately, I've not had the need for such a thing and prefer more verbose approaches nowadays, or I'd show you something with real application. :\


-[Все слова это только слова.]-