Difference between revisions of "0ADA"
Jump to navigation
Jump to search
(Created page with "{{OpCode | games = {{Icon|t}} (with CLEO) | description = Reads formatted text from the file | syntax1 = 0ADA: [''var''] = scan_file [''file''] format "[''string...") |
m |
||
Line 51: | Line 51: | ||
The input file contains the following line: | The input file contains the following line: | ||
− | <syntaxhighlight lang=" | + | <syntaxhighlight lang="text"> |
10.0 20.0 30.0 | 10.0 20.0 30.0 | ||
</syntaxhighlight> | </syntaxhighlight> | ||
[[Category:CLEO Opcodes]] | [[Category:CLEO Opcodes]] |
Revision as of 05:20, 16 September 2016
(with CLEO)
- Description
- Reads formatted text from the file
- Syntax
- 0ADA: [var] = scan_file [file] format "[string]" ( [any] ... )
- Parameter
- [var]
- Variable to store the number of data assigned
- [string]
- Formatted text specifying how to read the file (see
fscanf
for explanation) - [file]
- The handle of the file
- [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