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

struct

struct name {

Declares a custom struct type in your script.
Structs allow you to group together related variables in order to make your script more structured and readable. For example, suppose that wanted to store some information on weapons that the player could carry. You could declare the variables like this:

int swordDamage;
int swordPrice;
String swordName;
but that quickly gets out of hand and leaves you with tons of variables to keep track of. This is where structs come in:
struct Weapon {
  int damage;
  int price;
  String name;
};
Now, you can declare a struct in one go, like so:
Weapon sword;
sword.damage = 10;
sword.price = 50;
sword.name = "Fine sword";
Much neater and better organised. You can also combine structs with arrays:
// at top of script
Weapon weapons[10];
// inside script function
weapons[0].damage = 10;
weapons[0].price = 50;
weapons[0].name = "Fine sword";
weapons[1].damage = 20;
weapons[1].price = 80;
weapons[1].name = "Poison dagger";
structs are essential if you have complex data that you need to store in your scripts.

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