Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: nneader on Mon 24/06/2013 22:10:31

Title: Understanding the Scripts Node
Post by: nneader on Mon 24/06/2013 22:10:31
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....


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:


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


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!
Title: Re: Understanding the Scripts Node
Post by: Ghost on Mon 24/06/2013 22:22:34
Imports are placed in the script HEADER, are you putting them there?
Title: Re: Understanding the Scripts Node
Post by: nneader on Mon 24/06/2013 22:30:03
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?

import function my_awesome_thingy();
Title: Re: Understanding the Scripts Node
Post by: Ghost on Mon 24/06/2013 22:56:14
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) Select

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


ExtenderFunctions.ash then needs:

Code (AGS) Select
import function DoTheBaconDance();

From now on, you can call the function from anywhere in your game.
Title: Re: Understanding the Scripts Node
Post by: nneader on Mon 24/06/2013 23:05:39
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.
Title: Re: Understanding the Scripts Node
Post by: Ghost on Tue 25/06/2013 00:15:07
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.