struct problem

Started by Shade, Mon 26/09/2005 18:25:43

Previous topic - Next topic

Shade

here is what i have in my script header:

Code: ags
struct ItemStats{
 int   buy;
 int   sell;
 String name;
};


and this i have in my global script:

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

Ashen

#1
AFAIK, you can't set the values outside of a function - try moving the:
Code: ags

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.
I know what you're thinking ... Don't think that.

strazer

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.

Shade

didn't know that... :D
i thought i am god and i can do everything...but i found my master in ags... :D
thx

SMF spam blocked by CleanTalk