It is quite hard to place ELSE - any easier way?

For questions about using Classic.

Post » Thu Jun 14, 2012 2:42 pm

Currently I am having trouble with placing else in the event sheets, especially when I try to connect the else with the right condition.

For instance, take a look here:



if (user press Z){
if (weapon is 1){
    if (user press UP){
      //shoot up
    }else if (user press DOWN){
      //shoot down
    }else{
      //shoot forward
    }
}else if (weapon is 2){
    if (user press UP){
      //shoot up
    }else{
      //shoot forward
    }
}
}


Something like that. This is just one fraction of something bigger. There are more ELSE but placing these ELSE are quite a pain. It is very hard to snap them in the right places. Are there easier ways to deal with placing ELSE?
B
2
G
1
Posts: 38
Reputation: 526

Post » Thu Jun 14, 2012 9:13 pm

Could you please explain, what you want to achieve?
Maybe I could suggest an alternative, but I need to know, what kind of game and effect you want to have.
B
24
S
9
G
2
Posts: 294
Reputation: 3,160

Post » Thu Jun 14, 2012 9:37 pm

Dont use else that too buggy, instead use a structure like and equivalent to C++ switch.

something like this:

+ MouseKeyboard: Player 1 "fire" is down
+ player: Value 'weapon' Equal to 0

    + MouseKeyboard: Player 1 "upkey" is down
      -> player: Set animation to "fire_up_weapon0"

    + MouseKeyboard: Player 1 "downkey" is down
      -> player: Set animation to "fire_down_weapon0"

+ player: Value 'weapon' Equal to 1

    + MouseKeyboard: Player 1 "upkey" is down
      -> player: Set animation to "fire_up_weapon1"

    + MouseKeyboard: Player 1 "downkey" is down
      -> player: Set animation to "fire_down_weapon1"




B
4
S
1
G
1
Posts: 69
Reputation: 863

Post » Thu Jun 14, 2012 10:42 pm

You can do "Else if" like this:
if (weapon is 1){
    if (user press UP){
      //shoot up
    }else{
        if (user press DOWN){
        //shoot down
        }else{
        //shoot forward
        }
}else{
    if (weapon is 2){
        if (user press UP){
        //shoot up
        }else{
        //shoot forward
        }
    }
}

"Else if" is like puting an "if" inside an "else"...
B
22
S
7
G
5
Posts: 90
Reputation: 3,430


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 9 guests