Adventure Game Studio

AGS Support => Advanced Technical Forum => Topic started by: TheMagician on Tue 15/11/2005 20:45:39

Title: importing a function with enum [solved]
Post by: TheMagician on Tue 15/11/2005 20:45:39
This might be a stupid question but just a few minutes ago this module header stopped working:

=======================
enum DecisionQuestion {
  eOverwrite, eDelete
};

struct SaveLoad {
  import static function DecisionGUI_Yes (enum);    // <-----this line causes the error
};

=======================

It says "Parse error at enum".

What did I change/forget?
Thanks in advance!

Stefan
Title: Re: importing a function with enum - problem
Post by: Rui 'Trovatore' Pires on Tue 15/11/2005 21:07:06
Shouldn't there be something after that "enum"?
Title: Re: importing a function with enum - problem
Post by: DoorKnobHandle on Tue 15/11/2005 21:12:39
You need to change the line to:


import static function DecisionGUI_Yes (DecisionQuestion);


I am sure that you understand your syntax error now, once you see the "solution". If not, go ahead and ask! :=
Title: Re: importing a function with enum - problem
Post by: TheMagician on Tue 15/11/2005 22:03:08
@RUI:
Well there could be something after the enum (which would later show up in the autocomplete feature of the script editor) but I think it isn't necessary

@DKH:
Well, now I don't get an error in the header anymore.
But what do I have to write in the script when I define the function for the first time?
Right now I have in my module script:

===
static function SaveLoad::DecisionGUI_Open (    )
===

What do I have to put into the brackets?
If I put in:

static function SaveLoad::DecisionGUI_Open (DecisionQuestion)

it says: parameter doesn't match prototype.
Title: Re: importing a function with enum - problem
Post by: HeirOfNorton on Wed 16/11/2005 04:35:53
Try static function SaveLoad::DecisionGUI_Open (DecisionQuestion thisDecision)
or somesuch. Bear in mind, enum is not itself a type like int or char, its more like a typedef. The way AGS sees it, DecisionQuestion is the type, and must be used in the header on its own. When the function is defined, you have to use the type (DecisionQuest) AND an instance of the type (like thisDecision), just like how you would have, say:

struct MyStruct {
    function One (int);
}

function MyStruct::One (int thisInt) {
...
}

See what I mean?

HoN
Title: Re: importing a function with enum - problem
Post by: TheMagician on Wed 16/11/2005 14:14:15
Thanks for your explanation, HeirOfNorton!

I changed the code according to your descriptions and it seems to work perfectly now.
I think I've finally understood the way "enum" works .... at least until I have the next question  ;)

Stefan
Title: Re: importing a function with enum [solved]
Post by: monkey0506 on Wed 16/11/2005 16:53:41
And if you include an instance name in the import, it will show up in autocomplete, even though it's not necessary.  This could help if you had a function like:

import int do_something(int, int);

Then you could clarify what the parameters were for by saying like:

import int do_something(int max, int min);

Or some such.