Can I write this if statement shorter?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By MadJester

I have this line of code :

if Input.is_action_just_pressed('ui_up') && state != "Dodge"&& state != "Attack_I"&& state != "Attack_II"&& state != "Attack_III":

My question: Is there a shorter way to write the ‘state !=’ part?
Sorry for the dumb question i’m new to this.
PS: ‘state’ is a match statement

:bust_in_silhouette: Reply From: kidscancode
if Input.is_action_just_pressed('ui_up') and not state in ["Dodge", "Attack_I", "Attack_II", "Attack_III"]:

or you can split to multiple lines:

if Input.is_action_just_pressed('ui_up'):
    if not state in ["Dodge", "Attack_I", "Attack_II", "Attack_III"]:

There are probably other solutions depending on how the rest of your code is structured.

Thank you, this is great.

MadJester | 2018-10-07 20:56

:bust_in_silhouette: Reply From: Batti
if Input.is_action_just_pressed('ui_up')
     match state:
          "the state you desire":
               stuff that must happen

Instead of considering the state you do not want just check if the state is the one you need
Or also

if Input.is_action_just_pressed('ui_up') && state == "the state you need"

But btw all depends on how your code is structured

If I change my code i could use this indeed.
Never the less thank you for your suggestion.

MadJester | 2018-10-08 08:32