Jump to content

&&s and ||s


Recommended Posts

Let me think on that logic.

 

Break up the logic so it's less confusing

If dz_mcm.head_toggle == True && !Target.IsInCombat()
    if env == "playerh" || env == "dwelling"
        ; stuff
    else
        ; stuff
    endif
else
     ; stuff
endif

So if any of those first statement is false, the || statements wont run at all. (yes nested if statements is possible)

 

The statement in your post is basically this: if any of those are false, the body of the statement wont run.

Edited by Rasikko
Link to comment
Share on other sites

The ori

 

Will this:

If dz_mcm.head_toggle == True && !Target.IsInCombat() && env == "playerh" || env == "dwelling"

ever check for env == "dwelling" ?

I need the toggle to be true, the target to not be in combat, and the env variable to be either playerh or dwelling.

 

diziet

 

Yes this will work. If env == "playerh" is false, it will move on to env == "dwelling" and if that is true will continue. Script conditions I've found follow the same logic as CK conditions which you can read more about here: https://www.creationkit.com/index.php?title=Conditions. Rasikko's method is great for more complex script conditions.

Link to comment
Share on other sites

You can use 'puddles' to help break things up if you prefer to reduce your IF statements

If ( dz_mcm.head_toggle == True && !Target.IsInCombat() ) && ( env == "playerh" || env == "dwelling" )

You can use multiple lines to help break things up while retaining a single IF statement

If dz_mcm.head_toggle == True && !Target.IsInCombat() \
  && (env == "playerh" || env == "dwelling")

It all depends on what you want to do. If you need to do things when one of the conditions is different while the others are still the same, check for it as its own condition statement inside the others.

Link to comment
Share on other sites

You can use 'puddles' to help break things up if you prefer to reduce your IF statements

If ( dz_mcm.head_toggle == True && !Target.IsInCombat() ) && ( env == "playerh" || env == "dwelling" )
You can use multiple lines to help break things up while retaining a single IF statement
If dz_mcm.head_toggle == True && !Target.IsInCombat() \
ÃÂ  && (env == "playerh" || env == "dwelling")
It all depends on what you want to do.ÃÂ If you need to do things when one of the conditions is different while the others are still the same, check for it as its own condition statement inside the others.

I came here to say the first thing. Wrapping conditions in parentheses is a good way to make your complex checks more strict syntactically. Out of habit I always use parentheses in if statements anyway because some programming languages require them.

 

As previously pointed out though, it might be better to spread complex conditions into nested if statements, or even separate ones, especially if there's a few OR checks as well.

Link to comment
Share on other sites

  • 3 months later...

Just necroing this to add that it turns out that

a) I clearly didn't communicate well enough, because...

b) It doesn't work the way I thought it would, and...

c) The other suggestions would have!

 

The line

If dz_mcm.head_toggle == True && !Target.IsInCombat() && env == "playerh" || env == "dwelling"

seems to be returning True when env == dwelling, even if everything else is false,

splitting the If statments does what I expect it to. I got schooled on my mod comments page:)

Should have paid attention at school here!

 

diziet

Link to comment
Share on other sites

This is one where parenthesis are kinda needed (imo). I'm a stickler for using them to keep from making logical mistakes in ~complex-ish (eyey crossing) logical representations. I don't program in Skyrim (yet), but I presume it's following standard javascript /programming rules, so parentheses aren't a crime, even if not "hip".

 

It can also help (in debugging) to break it down into substitutions (which can be purged later on if you want your code in compressed form (sans parenthesis, sans substitutions for whatever reason)

dwelling = (env == "dwelling")
home = (env = "playerh")
is_secure = (home || dwelling)
isnt_fighting = !Target.IsInCombat()
player_moving_head = (dz_mcm.head_toggle == True)

- ** player_moving_head: idk what dz_mcm.head_toggle actually is, so I'm winging it on interpretation...

 

So, that condenses to

if (player_moving_head && isnt_fighting && is_secure)
Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...