Which will work correctly?
#1

Hey,
Which of these will work correctly in my script:

pawn Код:
if(health > 10 || health < 50) // if health is more than 10  O R  if health is less than 50

//OR

if(health > 10 && health < 50) // if health is more than 10  A N D  if health is less than 50
With || or with && ?
Reply
#2

That depends on what you want it to do.
Reply
#3

I want to do something if player health is from 10 to 50 (any health point between 10 and 50)
Reply
#4

Depens if you want one of them or both. ||, &&

Quote:
Originally Posted by Justas [SiJ
]
I want to do something if player health is from 10 to 50 (any health point between 10 and 50)
Use && = AND
Reply
#5

Short answer: Then I think you should use the && one.
Reply
#6

If I'd use || when would it execute the code?

Like
pawn Код:
if(health > 10 || health < 50)
{

//CODE GOES HERE

}
Reply
#7

Quote:
Originally Posted by Justas [SiJ
]
If I'd use || when would it execute the code?
When health would be bigger than 10 or smaller than 50.
Reply
#8

Actually it doesn't check anything then because only one of these 2 statements have to be true, so every health value suits.
Reply
#9

Quote:
Originally Posted by Don Correlli
Quote:
Originally Posted by Justas [SiJ
]
If I'd use || when would it execute the code?
When health would be bigger than 10 or smaller than 50.
So if "health would be bigger than 10 or smaller than 50" with ||
what && do?
I think that && does what u said..
Reply
#10

Let's say health is 70

if(health > 10 || health < 50) // Only 1 has to be true and we have 1 true so...
{
Code will be called
}

if(health > 10 && health < 50) // Both have to be true, but we have only one true, so...
{
Code won't be called
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)