Problems with static function imports within struct (SOLVED)

Started by Akumayo, Thu 29/06/2006 08:22:49

Previous topic - Next topic

Akumayo

I have a similar struct declaration to the one below in one of my module headers:

Code: ags

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:
Code: ags

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


As well as this:
Code: ags

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
"Power is not a means - it is an end."

Khris

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) {...}

Akumayo

#2
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:
Code: ags

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


And, when called, it looks like this:
Code: ags

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
"Power is not a means - it is an end."

Ashen

Does the function need to be created as static, before being imported?

static function Some_Struct::MyFunction(String UserString, int UserInteger) {
...
}
I know what you're thinking ... Don't think that.

Akumayo

#4
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?
"Power is not a means - it is an end."

strazer

#5
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.

Akumayo

I'm not exactly sure what you mean.  I feel stupid.

Here's the script from the module header:
Code: ags

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


And here's the script from the module main script
Code: ags

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
"Power is not a means - it is an end."

Ashen

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:
Code: ags

static function JournalModule::AddEntry(String Text) {
//function contents
}
I know what you're thinking ... Don't think that.

Akumayo

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.
"Power is not a means - it is an end."

SMF spam blocked by CleanTalk