spacer graphic
spacer graphic
Montage of games AGS Logo
spacer graphic

 

spacer graphic
Menu
spacer graphic Home
About
News
Features
Download AGS
spacer graphic Games 
Games main page
Award Winners
Picks of the month
Short games
Medium length games
Full length games
In Production
Hints & Tips
Community
Forums
AGSers World Map
Member websites
Chat
Resources
Tutorials
FAQ
Knowledge Base
Downloads
Links
AGS-related links
* AGS Manual
  * Scripting
    * Script language keywords

Arrays

data_type name [ size ];

Arrays allow you to easily create several variables of the same type. For example, suppose you wanted to store a health variable for all the different characters in the game. One way would be to declare several different variables like this:

int egoHealth;
int badGuyHealth;
int swordsmanHealth;
but that quickly gets messy and difficult to keep up to date, since you need to use different script code to update each one. So instead, you can do this:
int health[50];
This example declares 50 int variables, all called health.
You access each seperate variable via its index (the number in the brackets). Indexes start from 0, so in this case the health array can be accessed by indexes 0 to 49. If you attempt to access an invalid index, your game will exit with an error.

Here's an example of using the array:

  health[3] = 50;
  health[4] = 100;
  health[player.ID] = 10;
this sets Health 3 to 50, Health 4 to 100, and the Health index that corresponds to the player character's ID number to 10.

See Also: Dynamic arrays


User comments and notes
There are currently no user comments on this page.
The user comment facility is currently disabled.