Skip to content
fromgate edited this page Jul 7, 2017 · 4 revisions

Conditional operator. This action is useful in cases where there is no desire to create additional activators. Or vice versa, it can allow you to choose and switch to one of the many activators.

IF_ELSE <if> <then:[text] | [RunActivator] | [RunActions]> <else:[text] | [RunActivator] | [RunActions]> [suffix]

Parameter Values ​​of the Description
<if> if:<"==", "!=", ">", "<", "&&", "||", "/^regex$/.test("value")", ... > The conditional operator
<then> then:<[text] / [RunActivator]> The result of the successful fulfillment of the condition
<else> else:<[text] / [RunActivator]> Result if the condition is not fulfilled
[suffix] suffix:<text> The suffix that is added to the placeholder %ifelseresult%. It is necessary if you need to apply several actions IF_ELSE
[RunActivator] run:{activator:<IdActivator>} Activator EXEC, which will be launched in relation to the player who performed this action.
All parameters are supported to run the activator EXEC
[RunActions] run:{actions:{action1:{action=param} action2:{action=param} actionN:{action=param}}} Run Actions allowed in the ReActions

Temporary placeholders set by this action

Placeholder Description
%ifelseresult[suffix]% The text result obtained from <then> or <else> after the condition <if>
[suffix] is needed if several actions should be applied IF_ELSE
%ifelsedebug% Shows the error you made in the if condition

The following temporary variables will be set in the activators that were called in accordance with the run parameter

Placeholder Description
%condition% The condition specified in if

Пример

Several activators implementing this action

  1. "Switching"
SNEAK:
  s:
    sneak: ANY
    actions:
    - IF_ELSE=if:{%sneak%==true} then:{&aYou sneak} else:{&cYou have risen}
    - MESSAGE=%ifelseresult%
  1. Application of several IF_ELSE actions in one activator. We check the speed value entered in the speed command.
COMMAND:
  speed_cmd:
    override: true
    regex: true
    command: cmd:speed arg1:*
    actions:
    - CANCEL_EVENT=true
    - IF_ELSE=if:{/^[0-9.-]+$/.test("%arg1%")} then:{%arg1%} else:{0}
    - 'MESSAGE=&aCheck for a number. &cSpeed ​​is set to: %ifelseresult%.'
    - IF_ELSE=if:{%ifelseresult% > 10} then:{10} else:{%ifelseresult%} suffix:_1
    - 'MESSAGE=&aCheck for a larger value. &cSpeed ​​is set to: %ifelseresult_1%.'
    - IF_ELSE=if:{%ifelseresult_1% < 0} then:{0} else:{%ifelseresult_1%} suffix:_2
    - 'MESSAGE=&aCheck for a lower value. &cSpeed ​​is set to: %ifelseresult_2%.'
    - FLY_SPEED=%ifelseresult_2%
    - WALK_SPEED=%ifelseresult_2%
    - 'MESSAGE=&a&lCurrent Speed: %ifelseresult_2%.'

Test this activator by entering commands:
/speed 2
/speed test
/speed 100
/speed -100

  1. Redirecting to external activators
SNEAK:
  s3:
    sneak: ANY
    actions:
    - 'IF_ELSE=if:{%sneak%==true} then:run:{activator:ifTrue} else:run:{activator:ifFalse}'
EXEC:
  ifTrue:
    actions:
    - 'MESSAGE=&6Player: &a%player% &eIF(&r%condition%&e) &aResult = TRUE'
  ifFalse:
    actions:
    - 'MESSAGE=&6Player: &a%player% &eIF(&r%condition%&e) &cResult = FALSE'
  1. Run Actions.
SNEAK:
  s4:
    sneak: ANY
    actions:
    - IF_ELSE=
        if:{%sneak%==true} 
        then:run:actions:{
            action1:{message=&aYou sneak}
        } 
        else:run:actions:{
            action1:{message=&cYou have risen}
        } 
  1. Multilevel action.
SNEAK:
  s5:
    sneak: ANY
    actions:
    - 'IF_ELSE=
        if:{%sneak%==true} 
        then:run:actions:{
            action1:{message=&6&lLevel1 TRUE}
            action2:{cmd=say &6&lLevel1 TRUE}
            action3:{IF_ELSE=
                if:{3==2}
                then:{message=&c&lLevel2 TRUE}
                else:run:actions:{
                    action1:{message=&c&lLevel2 FALSE}
                    action2:{IF_ELSE=
                        if:{2==2}
                        then:run:actions:{
                            action1:{broadcast=&e&lLevel3 TRUE}
                        }
                        else:{}
                    }
                }
            }
        } else:run:actions:{
            action1:{message=&6&lLevel1 FALSE}
            action2:{message=&6&lLevel1 FALSE 2}
        }'

Clone this wiki locally