Else If for Conditional Branches

Discussion in 'Editor Suggestions and Improvement' started by JayA, May 28, 2018.

?

Would you like this feature?

  1. Yes

    26 vote(s)
    65.0%
  2. No

    7 vote(s)
    17.5%
  3. Yes but not important

    7 vote(s)
    17.5%
  1. JayA

    JayA Veteran Veteran

    Messages:
    34
    Likes Received:
    11
    First Language:
    English
    Primarily Uses:
    RMMV
    Ahh okay, well then yeah, same issue. Now if there were a "break" event in RMMV, which would break you out of the current conditional branch only, that would be helpful (though still not as ideal as implementing Else If).
     
    #21
  2. Shaz

    Shaz Veteran Veteran

    Messages:
    35,321
    Likes Received:
    9,860
    Location:
    Australia
    First Language:
    English
    Primarily Uses:
    RMMV
    You mean something like Jump to Label?
     
    #22
  3. Landazar

    Landazar Veteran Veteran

    Messages:
    122
    Likes Received:
    46
    Location:
    Poland
    First Language:
    Polish
    Primarily Uses:
    RMMV
    As for me, better option would be completly removing Conditional Branch and put in it's place switch.
    if (statement) {do stuff;} else {do other stuff;} is too simple and does not allow to efficient create multiple conditions.

    switch(statement){
    case value: method; break;
    default: method_that_does_meet_condition_in_statement; break;
    }

    would create a very complex event branch with simplicity of if/else statement (aka Conditional Branch) because if/else works pretty much the same as if/else.
    And furthermore switch/case allows you put a method when statement doesn't match in any defined statement and even more, nest as many case's as you wish.

    a quick example:
    Code:
    switch(var a = 3) {
        case 1:
            writeText('This is a num 1');
            break;
        case 2:
            writeText('This is a num 2');
            break;
        default:
            writeText('This is a num 3 and does not match');
    }
    
    Of cource more advanced users will simply do that with Script: $someCustomScripting.method, but Script Event is limited to 12 lines...
     
    Last edited: Aug 4, 2018
    #23
  4. Autofire

    Autofire PICNIC Solver Veteran

    Messages:
    40
    Likes Received:
    19
    First Language:
    English
    Primarily Uses:
    RMMV
    Ehh, I don't think that a switch statement is a decent replacement for conditional branch. It only makes sense with number-based checks, as you're always checking the same value. If I want to do

    Code:
    if(isHappy) {
      cout << "YAY!";
    }
    else if(isHungry) {
      cout << "Is dinner ready?";
    }
    I can't easily replicate this with a switch statement, because these are two separate variables I'm checking. Being able to have an if-else is absolutely necessary.

    If you mean we can make each case have independent conditions, that's pretty similar to an if-elseif-else.

    Anyway, I think that being able to edit the "else" and to make it into an else-if seems pretty intuitive. It's also not something newer users would necessarily need to worry about because I don't think they'll find the feature unless they're looking for it.
     
    #24
  5. Landazar

    Landazar Veteran Veteran

    Messages:
    122
    Likes Received:
    46
    Location:
    Poland
    First Language:
    Polish
    Primarily Uses:
    RMMV
    @Autofire, my fault. I forgot to mention that switch statement actually has no point if you have only two values like in your example.
    And if game will be deployed for web browsers it may cause some troubles, because different web browsers has different approaches
    in executing switch statement.
     
    #25
  6. JayA

    JayA Veteran Veteran

    Messages:
    34
    Likes Received:
    11
    First Language:
    English
    Primarily Uses:
    RMMV
    I suppose that could work, but is two whole extra events you have to add to get the functionality needed, and that's with just one condition (the Label and the Jump to Label per condition).

    I agree that switch/case is similar, but just more limited than else-if would be. Mainly it's useful as a nicer syntax, and doesn't really provide many benefits over if/else anyway (and yes it has default, but that is essentially an else?).
     
    #26
  7. ChampX

    ChampX Veteran Veteran

    Messages:
    159
    Likes Received:
    87
    First Language:
    English
    Using default in switch is optional anyway. One thing switch is useful for is a clean way to actually have fall through where all subsequent statements execute. More often than not, using break is intentional, but sometimes omitting it can be useful to (provided the language allows it).

    Code:
    switch (powerup)
    {
    case HYPER_POWERUP:
         executeHyperPowerUp();
    case SUPER_POWERUP:
         executeSuperPowerUp();
    case NORMAL_POWERUP:
         executeNormalPowerUp();
    }
    In this example you could have three power ups called normal, super, and hyper. Each tier would activate all lower tier power ups to so super activates its power up as well as normal and hyper activates its power up along with super and normal. Situational but useful at times.

    Of course you could in current RPG Maker just use a series of ifs like the conditional branches offer now where you'd have to set each preceding if to have a condition that makes all subsequent ifs become true as well. Alternatively, you could jump to labels, but that's just messy!

    I would like the addition of both else if and switch if its feasible to add in the editor.
     
    #27
  8. JayA

    JayA Veteran Veteran

    Messages:
    34
    Likes Received:
    11
    First Language:
    English
    Primarily Uses:
    RMMV
    I agree, though would imagine "switch/case" should be under a different suggestion thread as it's a little out of scope.
     
    #28
  9. atoms

    atoms Veteran Veteran

    Messages:
    152
    Likes Received:
    60
    Location:
    United Kingdom
    First Language:
    English
    Primarily Uses:
    RMMV
    Yeah it can get messy the way it currently is, but if you use comments to try and track it I find that helps me remember where what is what with a lot of conditional branches.
     
    #29

Share This Page