Difference between revisions of "0ADA"
Jump to navigation
Jump to search
(highlight test) |
m |
||
Line 17: | Line 17: | ||
== Example == | == Example == | ||
The following example reads an XYZ coordinate point from a file. Upon success, press [[00E1|button 17 (attack)]] to teleport to the point. | The following example reads an XYZ coordinate point from a file. Upon success, press [[00E1|button 17 (attack)]] to teleport to the point. | ||
− | + | {{Pre|class=sb-code|1= | |
+ | <span class="k">const</span> | ||
FILE_HANDLE = <span class="nv">0@</span> | FILE_HANDLE = <span class="nv">0@</span> | ||
X_POS = <span class="nv">1@</span> | X_POS = <span class="nv">1@</span> | ||
Line 28: | Line 29: | ||
0AAB: file_exists <span class="s2">"input"</span> | 0AAB: file_exists <span class="s2">"input"</span> | ||
<span class="k">then</span> | <span class="k">then</span> | ||
− | 0A9A: FILE_HANDLE = openfile <span class="s2">"input"</span> mode <span class="m">0x72</span> <span class="c1">// r</span> | + | [[0A9A]]: FILE_HANDLE = openfile <span class="s2">"input"</span> mode <span class="m">0x72</span> <span class="c1">// r</span> |
0ADA: NUM_SCANNED = scan_file FILE_HANDLE format <span class="s2">"%f %f %f"</span> X_POS Y_POS Z_POS | 0ADA: NUM_SCANNED = scan_file FILE_HANDLE format <span class="s2">"%f %f %f"</span> X_POS Y_POS Z_POS | ||
0A9B: closefile FILE_HANDLE | 0A9B: closefile FILE_HANDLE | ||
Line 37: | Line 38: | ||
<span class="k">wait</span> <span class="m">10</span> | <span class="k">wait</span> <span class="m">10</span> | ||
<span class="k">if</span> | <span class="k">if</span> | ||
− | 00E1: player <span class="m">0</span> pressed_button <span class="m">17</span> <span class="c1">// attack key</span> | + | [[00E1]]: player <span class="m">0</span> pressed_button <span class="m">17</span> <span class="c1">// attack key</span> |
<span class="k">then</span> | <span class="k">then</span> | ||
− | <span class="k">while</span> 00E1: player <span class="m">0</span> pressed_button <span class="m">17</span> <span class="c1">// attack key</span> | + | <span class="k">while</span> [[00E1]]: player <span class="m">0</span> pressed_button <span class="m">17</span> <span class="c1">// attack key</span> |
<span class="k">wait</span> <span class="m">0</span> | <span class="k">wait</span> <span class="m">0</span> | ||
<span class="k">end</span> | <span class="k">end</span> | ||
− | + | [[0055]]: put_player <span class="nv">$PLAYER_CHAR</span> at X_POS Y_POS Z_POS | |
<span class="k">end</span> | <span class="k">end</span> | ||
<span class="k">end</span> | <span class="k">end</span> | ||
<span class="k">end</span> | <span class="k">end</span> | ||
<span class="k">end</span> | <span class="k">end</span> | ||
− | + | }} | |
The input file contains the following line: | The input file contains the following line: |
Revision as of 04:27, 18 January 2017
(with CLEO)
- Description
- Reads formatted text from the file
- Syntax
- 0ADA: [var] = scan_file [file] format "[string]" ( [any] ... )
- Parameter
- [file]
- The handle of the file
- [string]
- Formatted text specifying how to read the file (see
fscanf
for explanation) - [var]
- Variable to store the number of data assigned
- [any]
- Variables to assign the data (any data type)
This CLEO opcode reads formatted text from the file and assigns the data to variables. In Sanny Builder it is important that you disable case converting in order for the opcode to work as expected. In "Options..." under the "Formats" tab in the "Case converting" box, select "As is". Additional calls to this opcode while the same file is still opened starts the reading at the position where it last left off rather than the beginning.
Example
The following example reads an XYZ coordinate point from a file. Upon success, press button 17 (attack) to teleport to the point.
const FILE_HANDLE = 0@ X_POS = 1@ Y_POS = 2@ Z_POS = 3@ NUM_SCANNED = 4@ end if 0AAB: file_exists "input" then 0A9A: FILE_HANDLE = openfile "input" mode 0x72 // r 0ADA: NUM_SCANNED = scan_file FILE_HANDLE format "%f %f %f" X_POS Y_POS Z_POS 0A9B: closefile FILE_HANDLE if NUM_SCANNED == 3 then while true wait 10 if 00E1: player 0 pressed_button 17 // attack key then while 00E1: player 0 pressed_button 17 // attack key wait 0 end 0055: put_player $PLAYER_CHAR at X_POS Y_POS Z_POS end end end end
The input file contains the following line:
10.0 20.0 30.0
Keywords
read, scan, file, format