Difference between revisions of "0ADA"
Jump to navigation
Jump to search
m |
|||
Line 3: | Line 3: | ||
| description = Reads formatted text from the file | | description = Reads formatted text from the file | ||
| syntax1 = 0ADA: [''var''] = scan_file [''file''] format "[''string'']" ( [''any''] ... ) | | syntax1 = 0ADA: [''var''] = scan_file [''file''] format "[''string'']" ( [''any''] ... ) | ||
− | | p1t = ['' | + | | p1t = [''file''] |
− | | p1d = | + | | p1d = The [[0A9A|handle of the file]] |
| p2t = [''string''] | | p2t = [''string''] | ||
| p2d = Formatted text specifying how to read the file (see <code>[http://en.cppreference.com/w/c/io/fscanf fscanf]</code> for explanation) | | p2d = Formatted text specifying how to read the file (see <code>[http://en.cppreference.com/w/c/io/fscanf fscanf]</code> for explanation) | ||
− | | p3t = ['' | + | | p3t = [''var''] |
− | | p3d = | + | | p3d = Variable to store the number of data assigned |
| p4t = [''any''] | | p4t = [''any''] | ||
| p4d = Variables to assign the data (any data type) | | p4d = Variables to assign the data (any data type) |
Revision as of 01:00, 20 November 2016
(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