Adventure Game Studio

AGS Support => Advanced Technical Forum => Topic started by: brewton on Sun 21/05/2017 21:20:06

Title: Custom enums across scripts
Post by: brewton on Sun 21/05/2017 21:20:06
Hi. I've got an enum set in the header of my global script. I'm modifying 9verbs template.
In guiscript I'm not able to use these enumerated values, getting an "undefined symbol" error.

Here's how I have it set up in my global header.
Code (ags) Select
enum pc_char { // differentiates playable versions of characters from others
  pc_eOne,
  pc_eTwo,
  pc_eThree,
  pc_eFour,
  pc_eFive,
  pc_eSix
};


Here's the code in the other script that throws the error.
current_kid is a global variable that is checked via a function called in repeatedly_execute.

Code (ags) Select

    else if (action == eGA_Ability) { // ability verb setup
      if (current_kid == pc_eOne) tresult = "SPOILER %s";
      else if (current_kid == pc_eTwo)  tresult = "SPOILER %s";
      else if (current_kid == pc_eThree)  tresult = "SPOILER %s";
      else if (current_kid == pc_eFour)  tresult = "SPOILER %s";
      else if (current_kid == pc_eFive)   tresult = "SPOILER %s";
      else if (current_kid == pc_eSix) tresult = "SPOILER %s";
    }


I've tried importing the enum to guiscript, but that didn't work.
What am I doing wrong?
Title: Re: Custom enums across scripts
Post by: Crimson Wizard on Sun 21/05/2017 21:22:35
You need to make sure enum is declared in the topmost script header in the modules list. Only same script and scripts below will be able to use it.
Title: Re: Custom enums across scripts
Post by: brewton on Sun 21/05/2017 21:27:00
That's an odd solution. Thanks!  :-D
Title: Re: Custom enums across scripts
Post by: Crimson Wizard on Sun 21/05/2017 22:06:42
Quote from: brewton on Sun 21/05/2017 21:27:00
That's an odd solution.

That is how AGS script works.

From the manual (http://www.adventuregamestudio.co.uk/wiki/Multiple_Scripts):
Quote
The order of the scripts is important. A script can only use functionality from other scripts that come before it in the list, so the Move Up and Move Down options allow you to adjust the order. The global script is always at the bottom so that it can access all other scripts, and room scripts are automatically provided with access to all the scripts.
Title: Re: Custom enums across scripts
Post by: brewton on Sun 21/05/2017 22:47:26
Ah, I must have missed that part. Thanks again.

As an aside, it seems that there's no Move Up and Move Down options in either AGS v3.4.0.16 or AGS v3.4.1.3.
I managed to get it working by creating a new script.
Title: Re: Custom enums across scripts
Post by: Crimson Wizard on Sun 21/05/2017 23:20:48
Quote from: brewton on Sun 21/05/2017 22:47:26
As an aside, it seems that there's no Move Up and Move Down options in either AGS v3.4.0.16 or AGS v3.4.1.3.
I managed to get it working by creating a new script.

Since 3.3.0 you can drag items around freely in most of the project tree.
I do not remember if Move Up/Down commands were removed by that reason or by mistake, but I will check that out.

EDIT: Yes, it looks like these commands were removed intentionally same time drag&drop was added (in AGS 3.2.2).