Jump to content
  • 0

&&(and) ||(or) doubt


JeffShadow90

Question


  • Group:  Members
  • Topic Count:  10
  • Topics Per Day:  0.00
  • Content Count:  15
  • Reputation:   0
  • Joined:  11/26/11
  • Last Seen:  

hI.

I have a doubt:

if I do && in a script like:

if (@nx =! @n1 && @n2 && @n3 && @n4 && ect....) {

is it going to consider true when @nx =! [@n1 and @n2 and @n3, and so on...] like it have to be always the same value for each different variable... right?

I need it to see if @nx is different from every single variable!

like saying that there MUST not be a variable with the same value of @nx in the list.

I thought that "||" could work but I'm afraid that it will consider only @n1 "OR" @n2 "OR" @n3

I mean: for example: @nx =! @n4 but it is = to @n3 will be the function activated anyway?

Tiny problem but so hard to describe :D

Thanks

Jeffo

Link to comment
Share on other sites

9 answers to this question

Recommended Posts


  • Group:  Members
  • Topic Count:  7
  • Topics Per Day:  0.00
  • Content Count:  130
  • Reputation:   43
  • Joined:  12/11/11
  • Last Seen:  

You must actually do a check for each variable.

You can use AND logic to make sure the value doesn't exist or OR logic to check if any contains the value.

if(@nx != @n1 && @nx != @n2 && ....)
if(@nx == @n1 || @nx == @n2 || ...)

Simple variable checks such as 'var && var && var' checks if they are not 0.

With the first code:

if (@nx != @n1 && @n2 && @n3 && @n4 && ect....) {

You check if @nx != @n1 and then you check that @n2 != 0, @n3 != 0 and so on.

  • Upvote 1
Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  75
  • Topics Per Day:  0.02
  • Content Count:  2223
  • Reputation:   593
  • Joined:  10/26/11
  • Last Seen:  

Yes, && (AND) is the correct operator if you want to check "if @nx is not equal to @n1, not equal to @n2, not equal to @n3".

if (@nx!=@n1 && @nx!=@n2 && @nx!=@n3) {

If you take the "not" part out and group the rest in parenthesis then you would use || (OR):

if ( !(@nx==@n1 || @nx==@n2 || @nx==@n3) ) {

"if not (@nx equal to @n1, or @nx equal to @n2, or @nx equal to @n3)"

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  31
  • Topics Per Day:  0.01
  • Content Count:  967
  • Reputation:   53
  • Joined:  11/13/11
  • Last Seen:  

@ BrianL

i have a question

is it possible to improve that or will rA improve that

as you said

if ( !(@nx==@n1 || @nx==@n2 || @nx==@n3) ) {

like making it short

since @nx is repeated 3x

is it possible to make

if( !(@nx == @n1,@n2,@n3) ) {

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  75
  • Topics Per Day:  0.02
  • Content Count:  2223
  • Reputation:   593
  • Joined:  10/26/11
  • Last Seen:  

No I don't think we'll be changing the syntax.

And if anything was changed, it would NOT be

if( !(@nx == @n1,@n2,@n3) ) {

Most languages that do support checking multiple values have a separate operator or function.

ex: SQL - IF @nx NOT IN (@n1,@n2,@n3)

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  31
  • Topics Per Day:  0.01
  • Content Count:  967
  • Reputation:   53
  • Joined:  11/13/11
  • Last Seen:  

i see

>_<

thanks for the info~

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  9
  • Topics Per Day:  0.00
  • Content Count:  379
  • Reputation:   304
  • Joined:  11/10/11
  • Last Seen:  

@KeiKun

It's bad to implement some things like this (the script engine is already enough weird).

BUT you can make functions for stuff like this.

function equal {
set .@i,1;
while ( getarg(.@i,0) == getarg(.@i,1) ) {
	if ( getarg(.@i) != getarg(0) )
		return 0;
	set .@i, .@i+1;
}
return 1;
}

if ( equal(.@a,.@b,.@c,.@d,.@e) ) {


}

  • Upvote 2
Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  1
  • Topics Per Day:  0.00
  • Content Count:  7
  • Reputation:   2
  • Joined:  12/11/11
  • Last Seen:  

You can also do some tricks if you're really lazy.

Something like this:

if(a == b && a == c && a == d && a == e && a == f)

can be written as this:

if(5*a - b - c - d - e - f == 0)

However if quickly gets obfuscated, so I wouldn't recommend it.

If the Athena script offers bitwise operators it's also possible to check multiple settings with bitmasks. :D

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  75
  • Topics Per Day:  0.02
  • Content Count:  2223
  • Reputation:   593
  • Joined:  10/26/11
  • Last Seen:  

if(5*a - b - c - d - e - f == 0)

*adds parenthesis* :D

if ((5*a - b - c - d - e - f) == 0)

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  9
  • Topics Per Day:  0.00
  • Content Count:  379
  • Reputation:   304
  • Joined:  11/10/11
  • Last Seen:  

[move a part to another topic]

@outofcuriosity and Brian

It's not always true:

if ( (5*5 - 3 - 7 - 5 - 6 - 4) == 0) // true but no all values = 5.

Edited by KeyWorld
  • Upvote 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...