Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Akumayo on Thu 29/06/2006 08:22:49

Title: Problems with static function imports within struct (SOLVED)
Post by: Akumayo on Thu 29/06/2006 08:22:49
I have a similar struct declaration to the one below in one of my module headers:


struct Some_Struct {
Ã,  import static function MyFunction(String UserString, int UserInteger=-1);
Ã,  ...
};


As far as I know, this should allow the user to call something like this:

Some_Struct.MyFunction("This is a string.");


As well as this:

Some_Struct.MyFunction("This is a string.", 7);


However, when I attempt to call the latter, I get an error during run-time:

Quote
Script link failed:Ã,  Runtime error:Ã,  unresolved import 'Some_Struct::MyFunction^7'

Any ideas of what I'm doing wrong?Ã,  (I'm new to calling functions as 'static')

-Regards, Akumayo
Title: Re: Problems with static function imports within struct
Post by: Khris on Thu 29/06/2006 08:31:14
I'm guessing here, so bear with me:

In the module try

function Some_Struct::MyFunction(String UserString, int UserInteger=-1) {
Ã,  ...
}

instead of

function MyFunction(String UserString, int UserInteger=-1) {...}
Title: Re: Problems with static function imports within struct
Post by: Akumayo on Thu 29/06/2006 08:33:37
The function is already written like you suggested.Ã,  I don't think that's the problem.Ã,  It's something about calling it as 'static' I think.Ã,  Thanks for trying though.

EDIT

Small update:

New code:

struct Some_Struct {
  import static function MyFunction(String MyString);
  ...
};


And, when called, it looks like this:

Some_Struct.MyFunction("This is a string.");


The error now reads:
Quote
Script link failed:  Runtime error:  unresolved import 'Some_Struct::MyFunction^1'

Any help is still appreciated.

-Regards, Akumayo
Title: Re: Problems with static function imports within struct
Post by: Ashen on Thu 29/06/2006 10:49:46
Does the function need to be created as static, before being imported?

static function Some_Struct::MyFunction(String UserString, int UserInteger) {
...
}
Title: Re: Problems with static function imports within struct
Post by: Akumayo on Thu 29/06/2006 10:53:45
Tried, apparently not.
Quote
'static' only applies to member functions.

Perhaps if I export the functions?Ã,  Is that even possible?
*Akumayo goes off to try.

EDIT:

Apparently, you CAN export functions, you just leave off their datatype "function" and their parenthesis "(...)", and the game gives you no trouble about it.

However, it does not stop the error from showing up.

Any other ideas?
Title: Re: Problems with static function imports within struct
Post by: strazer on Thu 29/06/2006 11:29:48
Can you please post exactly how you've written the function header in the module script?
You DO need the static keyword, but you have to leave out the -1, just as Ashen posted.

Edit: And if that fails, compare uppercase/lowercase letters. The struct, function and parameter names have to match exactly.
Title: Re: Problems with static function imports within struct
Post by: Akumayo on Thu 29/06/2006 11:36:36
I'm not exactly sure what you mean.  I feel stupid.

Here's the script from the module header:

struct JournalModule {
  import static function AddEntry(String Text);
  //some other functions
};


And here's the script from the module main script

function AddEntry(String Text) {
//function contents
}


And here's the exact error (generated on run-time):

Quote
Script link failed:  Runtime error:  unresolved import 'JournalModule::AddEntry^1'

What do I need to change?

(Thanks for the help so far)

-Regards, Akumayo
Title: Re: Problems with static function imports within struct
Post by: Ashen on Thu 29/06/2006 11:42:33
Look back at what KhrisMUC said:
Quote
In the module try

function Some_Struct::MyFunction(String UserString, int UserInteger=-1) {
  ...
}

instead of

function MyFunction(String UserString, int UserInteger=-1) {...}

So in the module, it should be:

static function JournalModule::AddEntry(String Text) {
//function contents
}
Title: Re: Problems with static function imports within struct
Post by: Akumayo on Thu 29/06/2006 11:46:59
Wow!

That worked!  I guess I just don't quite grasp how to use static functions yet.  I'm getting it though!

Thanks for all the help guys.