Adventure Game Studio

AGS Support => Advanced Technical Forum => Topic started by: spook1 on Fri 04/11/2005 21:23:36

Title: Array definition of struct? (SOLVED)
Post by: spook1 on Fri 04/11/2005 21:23:36
In my global script I define a struct and build an arry from it.
I get an error message;

Unexpected KlikPlek


I am not a very experienced programmer so I cannot see what I am doing wrong. Any ideas??

Here is my code:


struct klikplek {
   int nr;
   int x;
   int y;
   int view_nr;
   int x_width;
   int y_width;
  };


KlikPlek klikplek[30];
Title: Re: array definition of struct??
Post by: DoorKnobHandle on Fri 04/11/2005 21:44:08
This is a simple one. ;D

Imagine you'd declare an array of - say - integers.


int array[30];


First comes the type of the variable ('int' in this case) and then the name of the variable ('array' in this case).

Now what you have there would be something like:


array int[30];


It's simply the wrong way around.

Change your array definition line to this:


klikplek KlikPlek[30];


Now it should work.

By the way, what does "KlikPlek" mean in which language? Just curios.
Title: Re: array definition of struct??
Post by: spook1 on Fri 04/11/2005 22:27:28
Thanks for the clear explanation, really helpful!
I am learning so much about programminglanguage just by AGS ;-)

KlikPlek means something like KlickPlatz :-P

Initially I thought about naming my struct "hotspot", but since that is an AGS name I figured that it might bring me trouble, that's why I chose this Dutch word, well not really Dutch, I built this word myself, just like KlickPlatz is not really german I guess.

Cheers,
Martijn
Title: Re: array definition of struct??
Post by: Wretched on Sat 05/11/2005 01:39:30
As a general rule, and to avoid confusion, it's good practice to name structs with a 's' at the start, so you would have

struct sKlikPlek {
   int nr;
   int x;
   int y;
   int view_nr;
   int x_width;
   int y_width;
  };


sKlikPlek KlikPlek[30];

Also you need to watch your capitalization, you example would not work because of this.

I also use an 'e' for enums, and a 'g' for global variables, etc.
Title: Re: array definition of struct??
Post by: monkey0506 on Sat 05/11/2005 02:06:33
Well I've never heard of this 's' prefix business..and would find it hard to work with...nevermind confusing.  And using 'g'-s for global variables is definitely not a good idea seeing as AGS 2.7+ using g* for GUI script o-names.

But I suppose it's really a matter of user preference.
Title: Re: array definition of struct??
Post by: Elliott Hird on Sat 05/11/2005 19:09:26
v for global varibles and normal varibles too maybe?
b for buttons, l for labels, y for yankees... :P
Title: Re: Array definition of struct? (SOLVED)
Post by: monkey0506 on Sat 05/11/2005 22:59:14
Just to clarify, 'e' is an accepted prefix for enumerated names, and if it's for some sort of module "eModuleName_".  But other than that and the built-in naming conventions, it really is up to the user.