Array definition of struct? (SOLVED)

Started by spook1, Fri 04/11/2005 21:23:36

Previous topic - Next topic

spook1

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];

DoorKnobHandle

This is a simple one. ;D

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

Code: ags

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:

Code: ags

array int[30];


It's simply the wrong way around.

Change your array definition line to this:

Code: ags

klikplek KlikPlek[30];


Now it should work.

By the way, what does "KlikPlek" mean in which language? Just curios.

spook1

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

Wretched

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.

monkey0506

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.

Elliott Hird

v for global varibles and normal varibles too maybe?
b for buttons, l for labels, y for yankees... :P

monkey0506

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.

SMF spam blocked by CleanTalk