Making a Custome Global Function

Started by Custerly, Thu 07/12/2023 18:47:33

Previous topic - Next topic

Custerly

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?

eri0o

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

Custerly

Thanks Eric0o, that was very helpful.

heltenjon

#3
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.  :)

SMF spam blocked by CleanTalk