Difference between revisions of "0ADA"

From GTAMods Wiki
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
 
(4 intermediate revisions by 2 users not shown)
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        = [''var'']
+
| p1t        = [''file'']
| p1d        = Variable to store the number of data assigned
+
| 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        = [''file'']
+
| p3t        = [''var'']
| p3d        = The [[0A9A|handle of the file]]
+
| 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)
Line 16: Line 16:
  
 
== 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 key) to teleport to the point.
<syntaxhighlight lang="scm">
+
{{Pre|class=sb-code|1=
const
+
<span class="k">const</span>
FILE_HANDLE = 0@
+
FILE_HANDLE = <span class="nv">0@</span>
X_POS = 1@
+
X_POS = <span class="nv">1@</span>
Y_POS = 2@
+
Y_POS = <span class="nv">2@</span>
Z_POS = 3@
+
Z_POS = <span class="nv">3@</span>
NUM_SCANNED = 4@
+
NUM_SCANNED = <span class="nv">4@</span>
end
+
<span class="k">end</span>
  
if
+
<span class="k">if</span>
     0AAB:  file_exists "input"
+
     0AAB:  file_exists <span class="s2">"input"</span>
then
+
<span class="k">then</span>
     0A9A: FILE_HANDLE = openfile "input" mode 0x72  // r
+
     [[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 "%f %f %f" 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
     if
+
     <span class="k">if</span>
         NUM_SCANNED == 3
+
         NUM_SCANNED == <span class="m">3</span>
     then
+
     <span class="k">then</span>
         while true
+
         <span class="k">while</span> <span class="k">true</span>
             wait 10
+
             <span class="k">wait</span> <span class="m">10</span>
             if
+
             <span class="k">if</span>
                 00E1:  player 0 pressed_button 17  // attack key
+
                 [[00E1]]:  player <span class="m">0</span> pressed_button <span class="m">17</span> <span class="c1">// attack key</span>
             then
+
             <span class="k">then</span>
                 while 00E1:  player 0 pressed_button 17  // attack key
+
                 <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>
                     wait 0
+
                     <span class="k">wait</span> <span class="m">0</span>
                 end
+
                 <span class="k">end</span>
                 0055: put_player $PLAYER_CHAR at X_POS Y_POS Z_POS
+
                 [[0055]]: put_player <span class="nv">$PLAYER_CHAR</span> at X_POS Y_POS Z_POS
             end
+
             <span class="k">end</span>
         end
+
         <span class="k">end</span>
     end
+
     <span class="k">end</span>
end
+
<span class="k">end</span>
</syntaxhighlight>
+
}}
  
 
The input file contains the following line:
 
The input file contains the following line:
<syntaxhighlight lang="txt">
+
<syntaxhighlight lang="text">
 
10.0 20.0 30.0
 
10.0 20.0 30.0
 
</syntaxhighlight>
 
</syntaxhighlight>
 +
 +
== Keywords ==
 +
read, scan, file, format
  
 
[[Category:CLEO Opcodes]]
 
[[Category:CLEO Opcodes]]

Latest revision as of 04:38, 18 January 2017

GTA III Vice City San Andreas (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 key) 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