Files
QtGameMaker/help/files/401_04_expressions.html
T

92 lines
2.5 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Expressions</title>
<link href="style.css" rel="stylesheet" type="text/css">
</head>
<body background="images/back.gif">
<!--START-->
<h3>Expressions</h3>
Expressions can be real numbers (e.g. 3.4), hexadecimal numbers, starting
with a $ sign (e.g. $00FFAA), strings between single or
double quotes (e.g. 'hello' or &#8220;hello&#8221;) or more complicated
expressions. (Note that strings can run over multiple lines!)
For expressions, the following binary operators exist (in
order of priority):
<ul>
<li>&amp;&amp; || ^^: combine Boolean values (&amp;&amp; = and, || = or,
^^ = xor)</li>
<li>&lt; &lt;= == != &gt; &gt;=: comparisons, result in true (1) or
false (0)</li>
<li>| &amp; ^: bitwise operators (| = bitwise or, &amp; = bitwise and, ^
= bitwise xor)</li>
<li>&lt;&lt; &gt;&gt;: bitwise operators (&lt;&lt; = shift left, &gt;
&gt; = shift right)</li>
<li>+ -: addition, subtraction</li>
<li>* / div mod: multiplication, division, integer division, and modulo
</li>
</ul>
<p>
Note that
value of <tt>x div y</tt> is the value of <tt>x/y</tt> rounded in the direction of zero to the nearest integer.
The <tt>mod</tt> operator returns the remainder obtained by dividing its operands.
In other words, <tt>x mod y = x - (x div y) * y</tt>.
Also, the following unary operators exist:
<ul>
<li>!: not, turns true into false and false into true</li>
<li>-: negates the next value</li>
<li>~: negates the next value bitwise</li>
</ul>
As values you can use numbers, variables, or functions that return a
value. Sub-expressions can be placed between brackets. All operators work
for real values. Comparisons also work for strings and + concatenates
strings. (Please note that, contrary to certain languages, both arguments
to a Boolean operation are always computed, even when the first argument
already determines the outcome.)
<p>
<b>Example</b>
<p>
Here is an example with some assignments.
<p>
<blockquote>
<pre>
{
x = 23;
color = $FFAA00;
str = 'hello world';
y += 5;
x *= y;
x = y &lt;&lt; 2;
x = 23*((2+4) / sin(y));
str = 'hello' + &quot; world&quot;;
b = (x &lt; 5) &amp;&amp; !(x==2 || x==4);
}
</pre>
</blockquote>
<!--END-->
</body>
</html>
<!-- KEYWORDS
hexadecimal numbers
expressions
operators
binary operators
unary operators
bitwise operators
boolean operators
logical operators
-->