Understanding the Scripts Node

Started by nneader, Mon 24/06/2013 22:10:31

Previous topic - Next topic

nneader

Ok, I have been trying to figure this out in my head concerning scripts.  I went through the manual and the forums and I think I have it, however, sometimes the conversation in the thread takes a weird turn.  At that point I scratch my head and wonder if I am getting it.

Here is how I think it should work...Am I right?

R Click on the Script's Node and choose New script (Name it whatever, because the name is only for the me...correct?) In this example, I name it BigBlue

In that new script, BigBlue, I put my code like this....

Code: ags

function my_awesome_thingy() 
{
  A BUNCH OF CODE HERE...
}


This is where I get confused, however, I believe I go up to the top of the BigBlue script and type:

Code: ags

import function my_awesome_thingy();


So right now, that function in the “BigBlue” script should be good to go...right?  I can access it in...let's say a room script, under an event.  For this example,  let's add this new function to room1's script under the Room_AfterFadeIn.  Should be...

Code: ags

function room_AfterFadeIn()
{
my_awesome_thingy();
}


This should work correctly, right?  If not, please show me.

Does the actual script name, “BigBlue” mean anything in AGS anywhere else?
Also, if I want to use my function, “my_awesome_thingy();” in another script (in the Script Node), I have to make sure it is ABOVE the one I want to use it in...right?

Thanks in advance!

Ghost

Imports are placed in the script HEADER, are you putting them there?

nneader

Ok, maybe I am not understanding what a script HEADER is then.

This is what I think it means...
At the top of the script above all events.

In my example:
at the top of script, BigBlue, I put the following code in...right?
Code: ags

import function my_awesome_thingy();

Ghost

#3
For each script there are two files. One is the script file, one the script header file.

NAME.ash is the script header. This is where imports and definitions (and enums if you need them) go.
NAME.asc is the actual script; this is where you write your functions.

For example:

ExtenderFunctions.asc contains this function:

Code: AGS

function DoTheBaconDance()
{
  player.say("I don't know how to do the bacon dance.");
}


ExtenderFunctions.ash then needs:

Code: AGS
import function DoTheBaconDance();


From now on, you can call the function from anywhere in your game.

nneader

THANK YOU! 
I didn't realize that the other file was the header. Every one kept referring to the HEADER, however, i just assumed it was just a part of the .asc file.  LOL.

Ghost

Glad to be of service. The term comes, as far as I know, from the C programming language.

Another note: When you work with scripts, their actual order in the project tree is important. You can only access functions from a script when it is "above" the script that makes the call. This is not important for room scripts, but if you use many scripts in a large project, you may need to move them around (by right-clicking a file and then selecting "move up/down").
As a rule of thumb, keep the gloablscript at the bottom.

SMF spam blocked by CleanTalk