Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Custerly on Thu 07/12/2023 18:47:33

Title: Making a Custome Global Function
Post by: Custerly on Thu 07/12/2023 18:47:33
Hi all,

I'm trying to make a global function that can be called anywhere.

I wrote the function into the top of the Global Script, like this:

function Dialogue()
{
// blah blah
}

But when I attempt to call it from an interaction in a room, I get this error: Undefinted Token '(function name)'.

I was able to circumvent this by importing the function in the room script, but my understanding was that functions made in the Global Script should not require importing later. Am I wrong in that, or have I made some error with the code?
Title: Re: Making a Custome Global Function
Post by: eri0o on Thu 07/12/2023 19:01:56
You are wrong. If you write something in one script and want to have it available to other scripts, the function has to be imported. The usual approach is to write the import in the header that pairs with that script - in your case would be the Global Script header.

https://adventuregamestudio.github.io/ags-manual/ImportingFunctionsAndVariables.html

The only thing special about global script is GUIs and character events are linked there. I think the name Global Script is something historical because I think AGS originally had only either Global Script or Room Script - you could not have other script modules.
Title: Re: Making a Custome Global Function
Post by: Custerly on Thu 07/12/2023 20:44:13
Thanks Eric0o, that was very helpful.
Title: Re: Making a Custome Global Function
Post by: heltenjon on Fri 08/12/2023 04:55:49
While this question really was about how to import a global function, I was wondering when I saw you making a function called "dialogue".

Just in case you haven't noticed, right-clicking on the Dialogs node in the editor will create a dialog for you. (Note the spelling.) https://adventuregamestudio.github.io/ags-manual/EditorDialog.html


Edit: He knew.  :)