| 1 | <html><head><meta name="robots" content="index,follow"><meta http-equiv="Content-Type" content="text/html; charset=utf-8"> |
| 2 | <title>Scripting 5.2. Expressions</title> |
| 3 | <style> |
| 4 | td { padding-left: 5pt; padding-right: 5pt; } |
| 5 | th { padding-left: 5pt; padding-right: 5pt; } |
| 6 | code { white-space: pre-wrap; } |
| 7 | dd { white-space: pre-wrap; } |
| 8 | </style> |
| 9 | </head><body bgcolor="#FFFFFF"> |
| 10 | |
| 11 | <table border=0 cellpadding=0 cellspacing=0><tr><td bgcolor="#CCCC00"><table border=4 cellpadding=9><tr><td align=middle bgcolor="#000000"><font face="Palatino,Times" size=6 color="#999900"><b> |
| 12 | Scripting 5.2. Expressions |
| 13 | </b></font></table></table> |
| 14 | <p>In a Praat script, you can use numeric expressions as well as string expressions.</p> |
| 15 | <h2>Numeric expressions</h2> |
| 16 | <p>You can use a large variety of <a href="Formulas.html">Formulas</a> in your script:</p> |
| 17 | <code> length = 10<br></code> |
| 18 | <code> height = length/2<br></code> |
| 19 | <code> area = length * height<br></code> |
| 20 | <code> writeInfoLine: “The area is ”, area, “.”<br></code> |
| 21 | <p>You can use numeric variables and formulas in numeric arguments to commands:</p> |
| 22 | <code> Draw line: 0, 0, length / 2, 2 * height<br></code> |
| 23 | <p>You can use numeric expressions in assignments (as above), or after <b><code><font size=+1>if</font></code></b>, <b><code><font size=+1>elsif</font></code></b>, <b><code><font size=+1>while</font></code></b>, <b><code><font size=+1>until</font></code></b>, and twice after <b><code><font size=+1>for</font></code></b>.</p> |
| 24 | <h2>String expressions</h2> |
| 25 | <p>You can use a large variety of <a href="Formulas.html">Formulas</a> in your script:</p> |
| 26 | <code> addressee$ = “Silke”<br></code> |
| 27 | <code> greeting$ = “Hi ” + addressee$ + “!”<br></code> |
| 28 | <code> writeInfoLine: “The greeting is: ”, greeting$<br></code> |
| 29 | <p>You can use string variables and formulas in numeric arguments to commands:</p> |
| 30 | <code> Draw line: 0, length (greeting$), 0, 100<br></code> |
| 31 | <code> Draw line: 0, if answer$ = “yes” then 20 else 30 fi, 0, 100<br></code> |
| 32 | <p>You can use numeric and string variables and formulas in string arguments to commands:</p> |
| 33 | <code> Text top: “yes”, “Hi ” + addressee$ + “!”<br></code> |
| 34 | <code> Text top: “yes”, left$ (fileName$, index (fileName$, “.”) - 1)<br></code> |
| 35 | <h2>Assignments from query commands</h2> |
| 36 | <p>On how to get information from commands that normally write to the Info window, see <a href="Scripting_6_3__Query_commands.html">Scripting 6.3. Query commands</a>.</p> |
| 37 | <h3>Links to this page</h3> |
| 38 | <ul> |
| 39 | <li><a href="Scripting.html">Scripting</a> |
| 40 | <li><a href="Scripting_5__Language_elements_reference.html">Scripting 5. Language elements reference</a> |
| 41 | </ul> |
| 42 | <hr> |
| 43 | <address> |
| 44 | <p>© ppgb 20180721</p> |
| 45 | </address> |
| 46 | </body> |
| 47 | </html> |