Adventure Game Studio

AGS Support => Advanced Technical Forum => Topic started by: nightmarer on Thu 29/04/2021 13:19:04

Title: Calling struct functions from external scripts
Post by: nightmarer on Thu 29/04/2021 13:19:04
Hello.

I have an struct which have some methods on it and it can be used from any room of the game.

Code (ags) Select
struct Actions{
  import static void Restablecer();
};


But now I am trying to call one of this method from another method not included in a room (in an external script) but AGS don't recognize it. And it says Error (linex): Undefined token 'Actions'
Code (ags) Select
function HangUpPhone() {
  Actions.Restablecer();
}


How can resolve this?
Title: Re: Calling struct functions from external scripts
Post by: Crimson Wizard on Thu 29/04/2021 13:31:34
In AGS a struct or function is only seen in script where it is declared, or in scripts which are below in the list.

Dialog scripts and room scripts are considered to be below everything else, but do not see each other.

The solution is to reorganize your scripts in an order of dependency, or pick certain structs/functions out into a new script and move it above ones where you have to use these.
Title: Re: Calling struct functions from external scripts
Post by: nightmarer on Thu 29/04/2021 14:31:50
Oh great. Now I understand.