How to define global function? [SOLVED]

Started by Pizzaman, Mon 24/01/2005 19:49:34

Previous topic - Next topic

Pizzaman

Hi all I am new here to this place.  I like all the adventure games here and find that this tool can have many possibilities.

Anyway, I am trying to define my function.  From what I read in the manual, I have the header in the script header:

import function fightsequence();

and then in my global script, I define it there..

function fightsequence()
{
...
}

but when it compiles it gives me this error:

"Already referenced name has import, you must define it before using it"

Please help.  THanks

-Pizzaman

Ishmael

have you put your function to the end or the beginning of the global script? If it's in the end, try moving it to the beginning, just a thought.
I used to make games but then I took an IRC in the knee.

<Calin> Ishmael looks awesome all the time
\( Ö)/ ¬(Ö ) | Ja minähän en keskellä kirkasta päivää lähden minnekään juoksentelemaan ilman housuja.

Etcher Squared Games

The previous post is correct.

I did exactly what you did, with the global function at the end of the global script.

I then in game_start tried to use the function.  After compile I get your error.

After moving the function to the beginning and tried again and it worked.

My question to all is this:
After defining the function in the header script, why does using the function BEFORE defining it break the compiler?  I would think that the header file would make it available at any point?
website: http://www.etcher2games.com/
email: etcher2games@yahoo.com
forum: http://www.etcher2games.com/forums

Anyone want to make my website for free?

Pizzaman

Yep it worked!

Quote from: etchersquaredgames on Mon 24/01/2005 21:09:35
My question to all is this:
After defining the function in the header script, why does using the function BEFORE defining it break the compiler?Ã,  I would think that the header file would make it available at any point?

Hmm, maybe the author wrote this compiler not exactly how C++ would parse the code.  Maybe some parts of it is checked in a different order than that of the C++ compiler?  At least that's what I learned from my Compiler's class.

-Pizzaman

Gilbert

The script compiler is single parse (I think) only, it does not support forward references, and it's never expected to be of full C++ complaint.

The header script does not apply to the global script, it apply to rooms only, so putting something in it won't let the global script use its content. In fact the header is mainly for 1) definition of stuff that are common to all rooms, and 2) import variables or functions defined in the global script so they can be used in rooms.

RickJ

Quote
The header script does not apply to the global script, it apply to rooms only, so putting something in it won't let the global script use its content. ...
This is not quite correct.  Althought it is true that this is the primary purpose of the header it is also true that the header is prepended to both room and global scripts before compilation.  I think it would be more accurate to say this about import statements contained within the header rather than the header itself.  This was perhaps, Gilbot's intended meaning; thought I would just add some clarification.

Ishmael

The header aplies to the global script aswell, simply by the sake of #define's...
I used to make games but then I took an IRC in the knee.

<Calin> Ishmael looks awesome all the time
\( Ö)/ ¬(Ö ) | Ja minähän en keskellä kirkasta päivää lähden minnekään juoksentelemaan ilman housuja.

Gilbert

Well, alright, the script header did effect on the global script, but after checking, (I think) it will behave this way:

- If you define a function, say, aa() at the bottom of the global script, and you import it in the script header, normally the function is available to rooms, okay.
- But if you call aa() halfway in the global script, it's not defined at that point yet so the compiler looks for "import" on top of the script (header is placed on top of scripts), which makes the compiler thinks it's been defined, so when it parses the definition part of aa() it'll generate an error as it thought that the function had been defined.
- If you instead define the function before it's used, it's okay, because the compiler will not check if the function is defined until it's called.

Anyway, I think it's normal and prevents the engine to produce erratic behaviour since it simply prevents forward references.

SMF spam blocked by CleanTalk