Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Hyacinthus on Wed 12/03/2025 19:13:14

Title: Error "function already defined" when loading old game files from 2010.
Post by: Hyacinthus on Wed 12/03/2025 19:13:14
Hi,

I don't know if it is a simple or a complex technical question... For various reason, I downloaded again a game that I did create in 2010 (last saved with version 3.2.0 of AGS). I downloaded the last version of Adventure Game Studio. However I am unable to build it...

I've not used Adventure Game Studio since fifteen years...

Here are the reported lines of error.
Code (report) Select
Failed to save room room0.crm; details below
guiscript.ash(203): Error (line 203): function 'Character::FaceDirection' is already defined

It was a long time ago, so it is difficult to understand why is such error... All I know is that the game worked at the time...

What does mean "is already defined"? Where would it be already defined?

There is indeed in guiscript.ash these lines:
Code (guiscript.ash) Select
// ============================= Player/character functions =======================================
import function freeze_player();
import function unfreeze_player();
import function SetPlayer(Character*ch);
import function FaceDirection (this Character*, eDirection dir);
import function EnterRoom(this Character*, int newRoom, int x, int y, eDirection dir, bool onWalkable);
import function Go();

And the script of the room0 indeed use that function:
Code (room0) Select
[...]
  pj2.Say("Clark-Williams, tu remonte la Plage.");
  pj0.FaceDirection(eDir_Left);
  pj2.Say("Pour ma part,");
  pj2.Say("Je vais tenter un contact radio.");
  pj1.Say("J'irai plutôt vers ce village, là-bas.");
  pj2.FaceDirection(eDir_Up);
  Wait(40);
  pj2.FaceCharacter(pj1);
  pj2.Say("Je l'avais vu, bien sûr.");
[...]
  pj2.Say("et proposer la forêt.");
  pj0.FaceDirection(eDir_Up);
  pj2.Say("...");
[...]
  pj1.Say("Le ya...");
  pj0.FaceDirection(eDir_Down);
  pj2.Say("Le yap.");

Do anyone know where shall I search a solution?

Thanks in advance,
H.
Title: Re: Error "function already defined" when loading old game files from 2010.
Post by: Khris on Wed 12/03/2025 20:00:03
The Character.FaceDirection method was added to the built-in API at some point after 3.2.0 came out.
Since the custom one in your game uses different enum values, you cannot simply remove the custom function.

A quick fix is to rename the custom one to FaceDirectionOld or something. Just let the script editor replace every occurrence of "FaceDirection" with "FaceDirectionOld" in guiscript's header and main script and all room scripts.

To do a clean refactor, you need to remove the function and header line from guiscript.asc / guiscript.ash, then replace every "eDir_Up" with "eDirectionUp" etc.
Title: Re: Error "function already defined" when loading old game files from 2010.
Post by: Crimson Wizard on Wed 12/03/2025 20:17:05
I think it should be safe to remove the custom FaceDirection function and assign builtin values to your enum.

I.e. if you declare something like this in the guiscript.ash
Code (ags) Select
enum eMyDirection
{
   eDir_Up = eDirectionUp,
   eDir_Down = eDirectionDown,
   // etc
};