Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / Constants cause code not to compile???

Author
Message
Bulsatar
13
Years of Service
User Offline
Joined: 19th Apr 2011
Location:
Posted: 28th Oct 2011 03:37
Hello Everyone,

So, started out on the code and put in some constants for this one. Hit run, nothing happened. Took out the constants and it compiles just fine...gggrrr. Here is the code:



As always, all help is much appreciated!!!
Hodgey
15
Years of Service
User Offline
Joined: 10th Oct 2009
Location: Australia
Posted: 28th Oct 2011 04:24
That is interesting because if you don't make 'player' a constant but still declare it, it compiles. This could be a bug and might be worth reporting on the bug reports board.

Bulsatar
13
Years of Service
User Offline
Joined: 19th Apr 2011
Location:
Posted: 28th Oct 2011 04:39
Same with Enemy...if I change the names to something like World_Player and World_Enemy it works....interesting. Does that mean that somehow Player and Enemy are reserved words???
Hodgey
15
Years of Service
User Offline
Joined: 10th Oct 2009
Location: Australia
Posted: 28th Oct 2011 05:41
Quote: "Does that mean that somehow Player and Enemy are reserved words??? "

I don't think so because if they were reserved words then making them globals or just even declaring them wouldn't work either.

Darkzombies
13
Years of Service
User Offline
Joined: 25th Dec 2010
Location: In multiple tabs, most likely youtube.
Posted: 28th Oct 2011 08:21
I dont see the problem, but theres no need to make them constants anyways, and always use words that you'll remember, like this.



Just a little basic help you'll need later on

Hodgey
15
Years of Service
User Offline
Joined: 10th Oct 2009
Location: Australia
Posted: 28th Oct 2011 08:54
Quote: "I dont see the problem"

Did you try compiling it?

Quote: "but theres no need to make them constants anyways"

Are you so sure?

IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 28th Oct 2011 15:16
Constants do check against reserved words because it causes bugs when they don't.

The reason that constants do this is that they are implemented as a text substitution.

For example, this:


Would be changed to this as the first stage of compilation:


Obviously, that's not correct code.

Bulsatar
13
Years of Service
User Offline
Joined: 19th Apr 2011
Location:
Posted: 28th Oct 2011 15:43
I understand how constants work and I appreciate your redesign of my initial code, however that does not address the issue of why it won't compile with Player or Enemy as a named constant.
Chris Tate
DBPro Master
16
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 28th Oct 2011 16:01
Bulsatar, Ian's point is that the compiler will replace any occurance of 'Player' in the source code to 1.

So functions like [AI Add Player] in Dark AI would become [AI Add 1]. And functions like [AI Add Enemy] will become [AI Add 2]

So that is why the error message says it is a reserved word.

Using [global Player = 1] will work because the compiler will not replace the occurances of Player variables with 1; it will recognize the difference between variables and functions.

Bulsatar
13
Years of Service
User Offline
Joined: 19th Apr 2011
Location:
Posted: 28th Oct 2011 16:06
gotchya! that makes sense...sorry for being dense
Stab in the Dark software
Valued Member
21
Years of Service
User Offline
Joined: 12th Dec 2002
Playing: Badges, I don't need no stinkin badges
Posted: 28th Oct 2011 18:22
Interesting, this appears to be a quirk of the DBPro compiler. Logically the compiler should not be parsing the names of constants out of DBPro commands.

We are going to add this to the list of indicators in our IDE, so it will alert the programmer to this naming conflict prior to sending the code to the compiler.


[img][/img]


WindowsXP SP3,Vista,Windows 7 SP1, DBpro v7.7RC7
Stab In The Dark Editor
The coffee is lovely dark and deep,and I have code to write before I sleep.
Chris Tate
DBPro Master
16
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 28th Oct 2011 18:45
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 28th Oct 2011 20:32
Quote: "Logically the compiler should not be parsing the names of constants out of DBPro commands. "

Why not?

We (the community) asked Lee to add that check in order to avoid exactly the kind of problem I described. It's a natural and unfortunate side-effect of having multi-word keywords in the language.

Login to post a reply

Server time is: 2024-11-24 01:14:17
Your offset time is: 2024-11-24 01:14:17