Already referenced...?

Started by SilverWizard_OTF, Wed 01/09/2004 20:31:45

Previous topic - Next topic

SilverWizard_OTF

Hello
My problem is a bit strange.

I have created some custom function and i have put them to the top of my Global Script. Well:
  function do_something() {
     //some code
     do_this();
     }

Do_this is an other custom function that i created. Well, when i do something like this (when i running a custom function via an other custom function), AGS engine gives this error: Error, the problem was in Main Script: Already referenced name as import.

Thanks for your help.

EDIT: Well, there is more! Now sometimes it gives an error when i create custom functions and tells the same things! It is a bit  madding
"All we have to decide is what to do, with the time that is given to us"

Pumaman

You have to declare a function before you use it.

Therefore, you cannot have this:

do_func();

in the script before this:

function do_func() {
// function code
}

Check the ordering of your functions.

SilverWizard_OTF

Yes, but:

I want to do something like this:

function do_this();
  //somecode
  do_that();                     //a custom function

function do_that();
   //some code
   do_this();

I want to do this for to create a "cycle". What shall i do for it?
"All we have to decide is what to do, with the time that is given to us"

TerranRich

I don't believe you can even do that. What exactly are you trying to do anyway? Maybe there is a workaround.
Status: Trying to come up with some ideas...

Ashen

For a workaround, you could try:
Code: ags

// main global script file

function do_this(); {
  //somecode
  RunCharacterInteraction (BLANK, MODE_USE);
}

function do_that(); {
   //some code
   do_this();
}



then import do_that() as a global function (if it isn't already), create a dummy character (BLANK), and have do_that() in its USE interaction. Then, when you call either of them, itt'l start the loop.
Since do_that() is called from outside the global script, it doesn't matter where you put it, so long as it's after do_this().
I know what you're thinking ... Don't think that.

SilverWizard_OTF

Well, here is a problem which ONLY a "Go to" script command could solve!

function do_this();
  //somecode
  do_that();                     //a custom function

function do_that();
   //some code
   do_this();

E.g. do_this is a function where Player1 do certain things.
E.g. do_that is a function where Player2 do some other things.
  Then, game returns to Player's1 function.

Something like that i wanted to do.
Personally, i think that problem is a kind of bug.
   Engine should scan the WHOLE script, before gives error, or at least the script header first.

"All we have to decide is what to do, with the time that is given to us"

Pumaman

Sounds like you'd get yourself into a recursive loop like that.

Why not have something like:

function do_all() {
  do_this();
  do_that();
}

I can't see a situation in which two functions need to call each other, there's usually a better way of doing it.

Snarky

#7
Actually, there are many cases where it makes sense to write mutually recursive functions. It often provides very elegant solutions to tricky problems.

The question of which function is first in the code is usually (and by usually I mean in C and C++) solved not with GOTO, but by splitting up the declaration and the definition of the functions, like this:

function do_this();
function do_that();

function do_this() {
Ã,  Ã, // some code...
Ã,  Ã, do_that();
}

function do_that() {
Ã,  Ã, // some other code...
Ã,  Ã, do_this();
}

That way, the compiler knows about all the functions in advance, and you can let them reference each other in any pattern you like. AGS doesn't allow this, though (at least not with the syntax I tried). In my opinion, it should. Or, as SilverWizard suggested, it should scan the entire script first so that the order doesn't matter.

SilverWizard_OTF

Well, i think Snarky has right. AGS engine should allow that trick.
"All we have to decide is what to do, with the time that is given to us"

SMF spam blocked by CleanTalk