Pair of Vintage Old School Fru
/ /

XtScript: Conjunction - Logical Operators

Learn how to use Conjunction in XtScript to make more expressive conditional statement in Conditional Operator

Conjunction operator is used to to make the conditional operator in XtScript to be more effective.

We can create a conditional statement containing different arguments by chaining them using conjunction operator.

XtScript Conjunction Operators
OperatorSyntax exampleSummary
or$a or $bThe condition is true either $a or $b return true
notnot $aThe condition is true if $a return false
not .. ornot $a or $bThe condition is true either $a return false or $b return true
not .. or not ..not $a or not $bThe condition is true either $a or $b return false

Quoted from syntax.xtgem.com:

There is NO if ... and ...
In Xtscripts if statement

Unlike in Javascript or PHP, XtScript doesn't have and as one of conjunction operator. We can use the not .. or not .. with else condition to simulate the "and".

Learn XtScript Conjunction Operators from examples

XtScript if .. or

- Code:
<!--parser:xtscript-->
	var $food = Orange
	var $fruit1 = Watermelon
	var $fruit2 = Orange

	if $food == $fruit1 or $food == $fruit2
		print You eat fruits. That's good and healthy
	else
		print Why you don't eat fruits?
	endif
<!--/parser:xtscript-->
You eat fruits. That's good and healthy
XtScript not

- Code:
<!--parser:xtscript-->
	var $number = 99

	if not $number < 100
		print \$number variable is more or equals to 100
	else
		print \$number variable is less than 100
	endif
<!--/parser:xtscript-->
- Result:
$number variable is less than 100
XtScript not .. or

- Code:
<!--parser:xtscript-->
	var $mammals = cat
	var $bird = parrot
	var $pet = cat
	var $question = Do you have a mammals pet?

	if not $pet == $bird or $pet == $mammals
		print $question Yes, I have a $pet. It is a mammals
	else
		print $question No, I don't have a mammals pet
	endif
<!--/parser:xtscript-->
- Result:
Do you have a mammals pet? Yes, I have a cat. It is a mammals
XtScript not .. or not ..

- Code:
<!--parser:xtscript-->
	var $smartphone = 200
	var $laptop = 700
	var $money = 500

	if not $money > 200 or not $money > 700
		print <p>I have $money. I can not buy new smartphone and laptop at same time</p>
	else
		print <p>I have $money. I have enough money to buy new smartphone and laptop at same time</p>
	endif

	# Let's change the $money variable value
	var $money = 750

	print <p>I just got a lottery! Now my money is $money</p>

	# Now $money variable has changed, let's redo the same if command with exact same conditions and arguments
	
	if not $money > 200 or not $money > 700
		print <p>I have $money. I can not buy new smartphone and laptop at same time</p>
	else
		print <p>I have $money. I have enough money to buy new smartphone and laptop at same time</p>
	endif
<!--/parser:xtscript-->
- Result:

I have 500. I can not buy new smartphone and laptop at same time

I just got a lottery! Now my money is 750

I have 750. I have enough money to buy new smartphone and laptop at same time

At the not .. or not .. conditions above, we are indirectly simulate the "and" when the condition return false and it is reaching else stage. Here is the logical explanation:
• If if not $money > 200 or not $money > 700 condition return true, it means $money is less than 200 or less than 700.
• If if not $money > 200 or not $money > 700 condition return false, it will reaching else stage which means it is a condition where are arguments return false = $money is more than 200 and $money is more than 700.