A struct is a user-definable custom type that can store multiple related ints and strings, which can be used to declare variables. Struct definitions and variables of struct types can only be declared globally (in system VC, outside of functions).

// The below defines a struct named 'User':
struct User
    int id;
    str name;
    int coolness;
    str pet_names[15];
    int bank_account_numbers[4];

// Now that 'User' is defined, we can make specific instances of it.
User mcgrue;
User vecna;

Inside a function, you can set values to structs: = "Ben"; = "Also Ben";
vecna.coolness = 7;
mcgrue.pet_names[0] = "Oliver";

Note that while you set the member variables of a struct, you cannot copy an entire struct's contents to another instance of that struct. This will not compile:

mcgrue = vecna; // error!

You can make arrays and multidimensional arrays of structs. This is generally the best way to use structs since you cannot copy them (like was shown in the previous example), so to move them around it's best to keep them all in the same array.

struct PointType
    int x, y, z;
    int color;

// Makes an array of 1000 points
PointType points[1000];

Inside a function, we can assign a point element in the points array:

// This set's element 3's x-variable to 20.
points[3].x = 20;

New in Verge 3.1, you can nest structures, which is sometimes useful. You have to still address each struct item by individual pieces, since Verge can't copy structs or do references at the moment.

struct spell
	string name;
	int mp_cost;

struct party_member
	string name;
	int hp, max_hp;
	int mp, max_mp;
	int atk;
	int def;
	spell spells[8]; // This creates 8 spell structures for each party member made!
party_member party_members[5]; // 5 party members.

party_members[0].name = "Bob";
party_members[0].atk = 6000;
party_members[0].spells[0].name = "Fire";
party_members[0].spells[2].name = "Wind";

party_members[0].spells[2] = party_members[0].spells[0];

There are no talkbacks on this documentation page yet. Post the first?

Post a new comment?

Doc Nav

Your docs
View All Docs

If you log in, you can edit the documentation, or create your own documents and tutorials!

Ben McGraw's lovingly crafted this website from scratch for years.
It's a lot prettier this go around because of Jon Wofford. is a member of the lunarnet irc network, and would like to take this opportunity to remind you that regardless how babies taste, it is wrong to eat them.