SA-MP Forums Archive
Which will work correctly? - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Which will work correctly? (/showthread.php?tid=88419)



Which will work correctly? - SiJ - 26.07.2009

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 && ?


Re: Which will work correctly? - refshal - 26.07.2009

That depends on what you want it to do.


Re: Which will work correctly? - SiJ - 26.07.2009

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


Re: Which will work correctly? - Correlli - 26.07.2009

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


Re: Which will work correctly? - refshal - 26.07.2009

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


Re: Which will work correctly? - SiJ - 26.07.2009

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

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

//CODE GOES HERE

}



Re: Which will work correctly? - Correlli - 26.07.2009

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.


Re: Which will work correctly? - MadeMan - 26.07.2009

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


Re: Which will work correctly? - SiJ - 26.07.2009

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..


Re: Which will work correctly? - MadeMan - 26.07.2009

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
}