Coding

 Reply to this postStart new topic

[SA]Arrays

Deji
post Apr 11 2010, 03:25 PM
Post #1


Coding like a Rockstar!

Group Icon

Posts: 1,468
From: ???
Joined: 28-May 09



Arrays


In San Andreas (and LCS and VCS, but I doubt many really mod that), we have a great new coding ability. Arrays are basically just variables, but they're indexed so we can get through them easily.


An example of how the indexing in an array works for a local variable:

0@
  1. 8
  2. 1
  3. 4
  4. Actor Handle
  5. Vehicle Handle
  6. 9
  7. 1.2442
  8. Object Handle


Here we can see the array has 8 indexes, as shown by the number to the left. Each index is a variable with another value stored in them. Just like normal variables, they can store the same things inside them, but that is because they are just normal variables.

The above list is the same as:

  • 0@ = 8
  • 1@ = 1
  • 2@ = 4
  • 3@ = 4
  • 4@ = Actor Handle
  • 5@ = Vehicle Handle
  • 6@ = 9
  • 7@ = 1.2442
  • 8@ = Object Handle


0@ does not contain the values of arrays inside itself, but is the starting point to other variables. Each variable is limited to 4 bytes, so you can only store one 4 byte value in each. All the values above are 4 bytes.


There are a few types of arrays. The simplest ones are for global variables:

SANNY
$var[0]
$var[1]
$var[2]


However these are technically not arrays (as far as I know). Sanny builder just adds them to replace groups of variables, thus making things easier for us to understand.


And supported by global and locals:

SANNY
0@(11@,10i)
$var(2@,40i)


The format is as goes:

CODE
{var}({index},{max}{type})


The {var} is our starting variable, which can be used to go forwards or backwards between variables.

The {index} is which offset we want to use. If the variable was 4, the variable would be 4@, as long as the starting var was 0@.

The {max} is a number to indicate the maximum amount of indexes that can be used.

The {type} indicates what kind of data we are storing to the variables, which lets the game decide how many variables each index should use:

CODE
f :: float - 4 bytes
i :: integer - 4 bytes
s :: short string - 8 bytes (or 1 byte per character)
v :: long string - 16+ bytes (or 1 byte per character)


However, the {type} is pretty pointless for differentiating between integers and floats, since they take up the same size. So you can use either. Sanny actually just adds the f and i as shortcuts to make things simpler, so you don't have to type 0x8. Either way, they compile as 0x8 - Which tells the game we are using a float OR integer array.

I'll add more info later... wink.gif


--------------------
Go to the top of the page
 
+Quote Post
Reply to this postStart new topic

1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members: