Double combined array and struct

Started by Atelier, Fri 21/10/2011 21:31:57

Previous topic - Next topic

Atelier

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:

Code: ags

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:

Code: ags

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.

Khris

Unfortunately not, structs can't have structs as members.

The only alternative is:

Code: ags
  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.

monkey0506

#2
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

Atelier


SMF spam blocked by CleanTalk