Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Atelier on Fri 21/10/2011 21:31:57

Title: Double combined array and struct
Post by: Atelier on Fri 21/10/2011 21:31:57
Hi, I'm rewriting the way my text game works, so all the data is catalogued in scripts rather than defined in individual rooms. I already know something like the following is possible:


quest[1].log[4] = "You spoke to Lord Woodfoot, who made it clear the gnomes will come to feast at Meyrnost if their vegan lifestyle is catered for.";


Each location can have items in it, so I would like to take the above a step further by doing something like the following:


loc[2].name = "Meyrnost Athenium";

loc[2].item[1].name = "Borromdock";
loc[2].item[1].desc = "A sweet smelling plant.";
loc[2].item[1].pickup = true;


Is this possible? I want to have the room items in a sub-class of the location (loc) class.
Title: Re: Double combined array and struct
Post by: Khris on Fri 21/10/2011 23:15:04
Unfortunately not, structs can't have structs as members.

The only alternative is:

  item[i(2, 1)].name = "Bottomdock";

where i(int loc, int item) will turn the parameters into an index. Say there are less than 100 items per location, then i would simply return loc*100+item.
Title: Re: Double combined array and struct
Post by: monkey0506 on Fri 21/10/2011 23:19:08
Are you familiar with multidimensional array indexing techniques for AGS? The basic idea (for a 2D array) is:

For a multidimensional array:

int array[A][B];

And:

... array[a][b] ...

Your index would be:

index = (a * B) + b;

For further dimensions it gets exponentially more complex and I'm on a bus..;D

But this technique could work for you.

LeKhris LeBeat me to LePost, but I don't LeCare. :P
Title: Re: Double combined array and struct
Post by: Atelier on Sat 22/10/2011 11:50:08
Ah ok, I'll try those. Thanks :)