Setting array values after declaration (inside structs)

Started by aedwards00, Wed 31/03/2010 18:47:37

Previous topic - Next topic

aedwards00

Hey, this isnt specifically an AGS problem but a general c++ one. I figured someone here might be able to help anyway though.

Is it possible to create an a structure containing an array, then create an array of those structures, and then assign values to each array element all in one go?

To illustrate:

Code: ags

struct Mystruct {
  int intarray[26];
}



Mystruct structarray[5];

structarray[0].intarray[26] = {VALUES HERE};


My coding is pretty rusty so there might be some really obvious errors in there, but thats the general effect I'm trying to achieve. If I remember right then I don't think it is possible, but I just don't really want to have to manually assign 26 values into each of 8 different arrays.

Gord10

It is possible. You could try it by yourself with


Code: ags

 int il=0, ij;
 while(il<5) {
   ij=0;
   while(ij<26) {
     structarray[il].intarray[ij]=il*26+ij;
     ij++;
   }
   il++;
   
 }



And use similar loops for displaying the values, which should be numbers between 0 and 130.

Don't forget to put a ; after your struct declaration.

Code: ags

struct Mystruct {
  int intarray[26];
};
Games are art!
My horror game, Self

aedwards00

Ah I think I didn't make clear that I have a set of specific values that I need to put into each array, each in a specific element.

Kweepa

In that case I think you're hosed, unless loading from a text file is acceptable.
Still waiting for Purity of the Surf II

aedwards00

I thought as much  >:(

I've kind of worked around the problem though by creating separate arrays initialised with the right values, then looping to copy from these into the arrays inside the structs. Its a bit ugly having a load of extra arrays hanging around but it gets the job done  :P

Thanks to both for your suggestions though :)

SMF spam blocked by CleanTalk