Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Shade on Mon 26/09/2005 18:25:43

Title: struct problem
Post by: Shade on Mon 26/09/2005 18:25:43
here is what i have in my script header:

struct ItemStats{
int   buy;
int   sell;
String name;
};


and this i have in my global script:

ItemStats myitems[10];
myitems[0].buy=10;        //line 96
myitems[0].sell=5;
myitems[0].name="Poster";
...


when i want to save my game i get this error:

error (line96): parse error: unexpected 'myitems'

i have done it like in the manual but it doesn't work. what am i doing wrong?
Title: Re: struct problem
Post by: Ashen on Mon 26/09/2005 18:33:05
AFAIK, you can't set the values outside of a function - try moving the:

myitems[0].buy=10;        //line 96
myitems[0].sell=5;
myitems[0].name="Poster";
// ... Etc

... into game_start.

EDITED: Since apparently you CAN have Strings in Structs now. Which is nice.
Title: Re: struct problem
Post by: strazer on Mon 26/09/2005 18:39:55
Yes, same reason why you can't do

int myvariable;
myvariable = 10;

outside of any functions. Outside you can define variables, but not set them to any value. The only exception is when you combine the two:

int myvariable = 10;

So just do as Ashen suggests.
Title: Re: struct problem
Post by: Shade on Mon 26/09/2005 18:42:27
didn't know that... :D
i thought i am god and i can do everything...but i found my master in ags... :D
thx