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.

Bug Reports / Setting Player or Enemy as a constant

Author
Message
Bulsatar
12
Years of Service
User Offline
Joined: 19th Apr 2011
Location:
Posted: 28th Oct 2011 06:02
Hello,

Found this one out by accident...the program will not compile when using #constant Player 1 or #constant Enemy 1. Here is the thread of discussion: http://forum.thegamecreators.com/?m=forum_view&t=190800&b=7&p=0
...and here is the code:
Hodgey
14
Years of Service
User Offline
Joined: 10th Oct 2009
Location: Australia
Posted: 28th Oct 2011 06:40 Edited at: 28th Oct 2011 06:40
The above doesn't compile on U77RC7 - Windows 7 32bit SP1

Quel
15
Years of Service
User Offline
Joined: 13th Mar 2009
Location:
Posted: 28th Oct 2011 11:11
There cannot be such variable as "Player 1"

It should read either Player_1 or Player1 if you must use numbers in it.

(and so do the change to the others)

-In.Dev.X: A unique heavy story based shoot'em ~35%
-CoreFleet: An underground commander unit based RTS ~15%
-TailsVSEggman: An Sonic themed RTS under development for idea presentation to Sega ~15%
IanM
Retired Moderator
21
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
12
Years of Service
User Offline
Joined: 19th Apr 2011
Location:
Posted: 28th Oct 2011 15:47
The structure of #Constant is declaration, string identifier, value.
That is what the code shows. I am not trying anything crazy or unique or wrong. I want Player to be a constant with the value of 1 and I want Enemy to be a constant with the value of 2. If I change the name to cPlayer or cEnemy or varPlayer or varEnemy, it compiles just fine. It is then obvious that the issue is with the exact string of both Player and Enemy. That should not be the case.
IanM
Retired Moderator
21
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 28th Oct 2011 20:40
Player and enemy are words that are included in existing DBPro commands. Allowing you to carry out the textual substitution you ask for does cause problems.

Release 5.4 included a change so that you can't use single letters, or use words within existing commands as constants.

Not a bug - it's working as designed.

Hodgey
14
Years of Service
User Offline
Joined: 10th Oct 2009
Location: Australia
Posted: 29th Oct 2011 01:40
What is confusing though is that you can do this:


But not this:


I'm assuming it's because #constant is a preprocessor directive and so is executed before the code is compiled?

Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 29th Oct 2011 13:42
IanM has just explained why the second fails. The problem is not that particular code but the simple fact that "player" is a reserved word.

I guess the first is allowed because there is no conflict, whereas with constants there might be and the compiler has no way of telling whether or not you intended (to use IanM's example)




rather than



However, I agree it would be helpful if this bit of the Help file were consistently implemented:

Quote: "RESERVED WORDS

Words that are deemed to be reserved are the commands of the language. You will not be able to name your variables, arrays or user functions if they exist as part of the language as commands. As you become more familiar with the language, you will be able to naturally avoid using reserved words for your variable and array names.
"


It seems that some command words are more reserved than others. Is there a way of finding the level of reservedness (other than blind experimentation)?

For example, the following accepts "player" but not "next":



I suspect this is a simple oversight - but there might be something more subtle behind all this.
Bulsatar
12
Years of Service
User Offline
Joined: 19th Apr 2011
Location:
Posted: 29th Oct 2011 16:46
Is there a listing of reserved words that crosses the gamut of all of the extensions that are out there????
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: 30th Oct 2011 16:47
Quote: "For example, the following accepts "player" but not "next""


The word “player” is not actually a reserved word in the DBPro language.
This is why DBPro compiler allows you to declare; variables, arrays, user defined data types, and functions by the name “player”.

The reason why constants can not be declared by the name “player”, “enemy”, or any other word which appears in a DBPro command is due to the method by which the DBPro pre-compiler for constants performs the text replacement.

As IanM has already pointed out, when the pre-compiler processes a line of code it simply performs a search for all instances of the name of a constant in the line of code. The problem is that the pre-compiler does not verify that an instance of the name of a constant is in fact an actual reference to a constant and not a word within a DBPro command. The pre-compiler for constants should parse out all DBPro commands in the line of code and then parse out the names of constants. The lack of this verification step is why the DBPro compiler has to treat the word “player” and “enemy” as a reserved word when handling constants.

[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.
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 30th Oct 2011 23:01
Quote: "The word “player” is not actually a reserved word in the DBPro language."


Quote: "The lack of this verification step is why the DBPro compiler has to treat the word “player” and “enemy” as a reserved word when handling constants."


Well, there you go. You've just made my point in a more roundabout way.

Login to post a reply

Server time is: 2024-04-19 00:13:05
Your offset time is: 2024-04-19 00:13:05