SOLVED 'string' not allowed inside a struct?

Started by pslim, Mon 16/05/2011 10:39:31

Previous topic - Next topic

pslim

Hey.

I've been struggling with figuring out how to organize my data and make it available to the various rooms that need it. I've searched the forums but can't seem to find a solution to the problem I'm having most currently.

There are several factions in my game (each represented by a particular leader), and for each leader there is a series of "info topics" available for the player to learn of. There is also an interface screen where I will need list boxes to be able to be populated by the strings that contain the various info topics (known ones only), where the player can click on individual topics (then other things happen that I haven't gotten to trying to code yet).

Right now I'm just trying to build the basic functionality of a faction and keep track of its information. Since I get the impression that you can't nest structs in other structs or use classes, I'm right now working with the idea of a separate struct for each faction, containing arrays for both the info strings themselves, but also bool arrays to keep track of whether the player has learned the corresponding info topic. I modeled this in c++ and got it to work okay (I'm just learning c++ so it's probably far from the best way of doing what I'm trying to do, but the limit of my ability at the moment to plan out), but I'm having trouble translating it to AGS.

Anyway, here is what I have atm:

In the header:

Code: ags
//Maude faction struct
struct Maude{

bool infoKnown[10]; //does the player know the info piece?
bool desireKnown[10];

string info[maxFacts]; //Maude Info statements
string desire[maxFacts]; 


};

import Maude maude;


and in the global script:
Code: ags

Maude maude;

//Arbitrary values for testing
maude.infoKnown[1] = true;
maude.infoKnown[4] = true;

maude.desireKnown[2] = true;
maude.desireKnown[6] = true;



maude.info[1] = "Maude hates walruses.";
maude.info[4] = "Maude wears a tupee.";

maude.desire[2] = "Maude wants a toaster.";
maude.desire[6] = "Maude wants world peace.";

export maude;



The error message I'm getting currently is, as the topic says, "'string' is not allowed inside a struct." Is this true, or is there something else wrong perhaps? If it is true, does anyone have any ideas about how I could handle what I'm trying to do without putting strings in my structs?

Any help would be appreciated, and I would also welcome better ideas on how to accomplish what I'm after if anyone happens to have any. Thanks!


Edit: Sorry, forgot to mention that I need the to be able to retrieve and also modify the bools from any room, although the strings will all be set from the start and not changed after that, if it makes a difference.
 

Gilbert

Use the type 'String' instead of 'string' and try again (yes, the case does make a difference). 'string' is now more or less an obsolete type (and you cannot even do '=' assignments with strings, only Strings can).

pslim

#2
<facepalm>

Thanks so much for that.


That error is gone, but I got another one which I thought might have to do with assigning values to variables outside a function, so I moved those arbitrary values into the game_start(). Now I'm getting a third error related to the declaration of the instance of Maude maude.

so I have this
Code: ags

Maude maude;


export maude;


It tells me "Already referenced name as import; you must define it before using it" and points to the "Maude maude;" line. I'm wondering if I've imported/exported incorrectly or if it's something else entirely that I've done wrong?  :-[


Edit: NM, I found some posts relating to it. I tried moving the declaration up to the top of the global script, not totally sure why it worked (it needed to be before the data was assigned to the various variables in the struct maybe?) but it did.

Thanks again Iceboty.
 

Khris

Quote from: pslim on Mon 16/05/2011 11:02:10(it needed to be before the data was assigned to the various variables in the struct maybe?)

Exactly, just like the error message said. The top of the script is a safe place, you can move these declarations down though as long as you aren't using them until after.

SMF spam blocked by CleanTalk