Adventure Game Studio | Forums

AGS Support => Beginners' Technical Questions => Topic started by: Chrille on Tue 19/01/2010 20:35:37

Title: Odd struct error message [SOLVED]
Post by: Chrille on Tue 19/01/2010 20:35:37
At the top of my global script there is some code for a struct which causes this error message:
"GlobalScript.asc(56): Error (line 56): Attributes of identifier do not match prototype"

Here is the code:
 struct InteractZone {
   String zoneTitle;
   int zoneImage;
   String zoneType;
 };

 InteractZone zoneHotspot[10];
 InteractZone zoneObject[10];


Line 56 is the one about 'InteractZone zoneHotspot[10];'
I tried searching both google and the forums for that exact error message and got no results at all. Could it be something further down in the script causing the error message?
Title: Re: Odd struct error message
Post by: Khris on Tue 19/01/2010 21:35:53
I copied that piece of code to a default game's global script, compiled fine for me.

Try moving the struct declaration to the header. If the instances are supposed to be global, you'll have to do that anyway.
Title: Re: Odd struct error message
Post by: monkey0506 on Tue 19/01/2010 22:19:41
That error message generally indicates that you have an improper import-definition relation somewhere. For example:

import String some_func();

int some_func() { // error -- function does not match import
}


Are you providing an import for this somewhere that could be different than the actual definition you've provided?
Title: Re: Odd struct error message
Post by: Chrille on Wed 20/01/2010 05:36:49
That was indeed the case, I'd accidently placed an int before the imports. Thanks!
Title: Re: Odd struct error message
Post by: Chrille on Wed 20/01/2010 21:27:23
I'd like to follow this up by asking exactly how you're supposed to export & import the InteractZone struct & the zoneHotspot bit in a script header because everything I tried gave me errors. In the end I placed the code mentioned earlier directly in the global script header.

But, I've run into a new problem with this struct. I mentioned in another recent thread I was planning on using it for retrieving data for hotspot interactions. In a room script, when the room loads, I set the attributes of the zoneHotspot array slots to things like maniHotspot[1]zoneTitle = "Bla"; etc.. So when the cursor is over a hotspot it's supposed to read from the array slot matching the ID of the hotspot the cursor is over.

The problem is that it doesn't return anything. When ask for, say, Display ("zoneHotspot[1].zoneTitle") in the room script, 'Bla' shows up perfectly. But asking for it from the global script I get nothing. I'm sure I did something wrong by putting the struct info in the header, but what?
Title: Re: Odd struct error message
Post by: monkey0506 on Wed 20/01/2010 21:53:19
Well if there's issues with the way it's being imported/exported then that would probably be the reason for the room script/global script discrepancies.

Particularly if you're defining the instances of your struct (i.e., zoneHotspot, zoneObject, etc.) in a script header then you're creating a new instance by that name for every single subsequent script.

The proper procedure for using structs across multiple scripts this way is:

// Header.ash

struct InteractZone {
  String zoneTitle;
  int zoneImage;
  String zoneType;
};

import InteractZone zoneHotspot[10];
import InteractZone zoneObject[10];

// Script.asc

InteractZone zoneHotspot[10];
export zoneHotspot;
InteractZone zoneObject[10];
export zoneObject;

// WhateverScript.asc

zoneHotspot[5].zoneTitle = "LOLWUT?";


The important things to take away from this:
Title: Re: Odd struct error message
Post by: Khris on Wed 20/01/2010 22:08:06
To elaborate a tiny bit:

An import line must contain the complete declaration line, e.g.

import int health;
import bool star_visible[100];
import function DrawStar(int x, int y, int radius);


An export line must contain the name, nothing else, e.g.

export health;
export star_visible;


Functions don't need to be exported.
Title: Re: Odd struct error message
Post by: Chrille on Thu 21/01/2010 20:55:13
Thanks for clearing things up! It took me quite a while to switch to the new interaction system but now it works perfectly.