Adventure Game Studio

AGS Support => Advanced Technical Forum => Topic started by: leone on Tue 03/05/2005 14:57:23

Title: Problem with compiling script in v2.7 [SOLVED]
Post by: leone on Tue 03/05/2005 14:57:23
Hi,

I loaded my game in AGS v2.7, but when I tried to test it I got a message:
Ã,  'There was an error compiling your script.
Ã,  Ã, Variable 'Direction' is already defined'

The variable in question is in 'repeatedly_execute' section of the Global script:

int CharId, Direction, dx, dy;

It is the part of the script that deals with keyboard control, which I copied from Hollister Man's script I found in the 'Controlling movement with keyboard' thread.

Since I just copied it, I don't know how it really works. I checked the rest of my script and didn't find any other place where variable 'Direction' is defined.
Title: Re: Problem with compiling script in v2.7
Post by: Rui 'Trovatore' Pires on Tue 03/05/2005 15:00:54
Try defining it in the beginning of the Golbal Script instead of in repeatedly_execute.

Failing that, rename it. I'm not too sure, but AGS now reserves some keywords, or something. Maybe this is such one...? Then again, I'm not totally sure, not even 10% sure...
Title: Re: Problem with compiling script in v2.7
Post by: Wretched on Tue 03/05/2005 15:03:26
I had same problem with a variable I had called Region, 2.7 has some new reserved variable names. You can just rename Direction to Direction2 and all occurances in your script. Ã, 
Title: Re: Problem with compiling script in v2.7
Post by: strazer on Tue 03/05/2005 15:17:04
That's right, "Direction" is the name of a built-in enum:

  enum Direction {
    eForwards = 1062,
    eBackwards = 1063
  }

"Direction2" would also work, but it is recommended that you write local variables (declared within a function) in lowercase letters.
So just change all occurrences of "Direction" to "direction".
Title: Re: Problem with compiling script in v2.7
Post by: Kinoko on Tue 03/05/2005 15:19:48
I had that exact problem but luckily I'd read up on it a bit beforehand so I knew what it was. I also had to change things like 'gui' in my script. I typically just put an 'a' on the end of them (don't know why, it just sticks in my head). Oh, and 'static', which was the variable name for a magic spell in my game. I was a bit surprised at that one, but it's understandable I guess.
Title: Re: Problem with compiling script in v2.7
Post by: strazer on Tue 03/05/2005 15:33:05
I renamed any such variables from object to objectid, for example, since they do contain the ID of the entity, not a pointer to it.

Here are all names reserved by built-in enum definitions:

bool
TransitionStyle
MouseButton
RoundDirection
RepeatStyle
Alignment
LocationType
CutsceneSkipType
DialogOptionState
eSpeechStyle
eVoiceMode
eCDAudioFunction
FileMode
EventType
BlockingStyle
Direction
WalkWhere

In retrospect, maybe they should have been named AGS_Direction and so on to reduce the probability of them being used as variable names by the user.
Title: Re: Problem with compiling script in v2.7
Post by: leone on Tue 03/05/2005 22:15:13
Thanks guys, my problem is of course solved.
By the way, v2.7 looks great :)