.float vs. float
Moderator: InsideQC Admins
7 posts
• Page 1 of 1
.float vs. float
I know the differences between a float and a .float.
I think How it goes is that a float is global(I don't know) their values can only be changed in defs.qc(Or whatever places it was defined). And .floats can be changed.
But what is the difference in this?
Or is it just For visual purposes(knowing why the Number is 25)
I would really like to know.
Thanks
I think How it goes is that a float is global(I don't know) their values can only be changed in defs.qc(Or whatever places it was defined). And .floats can be changed.
But what is the difference in this?
- Code: Select all
in defs.qc
float BROKEN = 25;
now in some qc file. Is there a difference between doing this
if (self.health <= BROKEN)
{
//do stuff;
}
and
if (self.health <= 25)
{
//do stuff;
}
Or is it just For visual purposes(knowing why the Number is 25)
I would really like to know.
Thanks
-

Mexicouger - Posts: 514
- Joined: Sat May 01, 2010 10:12 pm
.float is a field float. This means every entity has its own variable float value you can set, such as health. You use it like: self.mydotfloat = 1;
While a float is a global variable, it is not different per entity. An good example is the float time; This does not mean it cannot be changed, it just means its accessible across all functions.
These rules apply for any data-type you use as a .type or not. (.vector .entity .string)
In your example there is no difference in the code, however many use the first example as its more readable and if you have multiple tests like that it is significantly easier to just change the 1 variable than all of them.
While a float is a global variable, it is not different per entity. An good example is the float time; This does not mean it cannot be changed, it just means its accessible across all functions.
These rules apply for any data-type you use as a .type or not. (.vector .entity .string)
In your example there is no difference in the code, however many use the first example as its more readable and if you have multiple tests like that it is significantly easier to just change the 1 variable than all of them.
- GiffE
- Posts: 170
- Joined: Sun Oct 08, 2006 3:39 pm
- Location: USA, CT
The reason is not exactly visual. Using constants makes code easier to read and to change (can you imagine someone using "4096" instead "IT_MYNEWWEAPON" in a mod and later discovering that needs to change every occurence of "4096" because it's the value of the already existing "IT_AXE" ? ).
I know FrikaC made a cgi-bin version of the quakec interpreter once and wrote part of his website in QuakeC
(LordHavoc)
-

frag.machine - Posts: 2090
- Joined: Sat Nov 25, 2006 1:49 pm
by convention, macros are upper case.
QC does not traditionally support macros, so instead of macos they're regular constants, but still upper case.
globals that are initialised are considered constant by default.
globals that are not initialised can be set freely (ie: self is such a variable global).
(I'll not point out that fields are actually globals too, if defined with global scope, and when a field is defined within a function, then its a regular local variable and doesn't reserve field space, hence the find builtin)
QC does not traditionally support macros, so instead of macos they're regular constants, but still upper case.
globals that are initialised are considered constant by default.
globals that are not initialised can be set freely (ie: self is such a variable global).
(I'll not point out that fields are actually globals too, if defined with global scope, and when a field is defined within a function, then its a regular local variable and doesn't reserve field space, hence the find builtin)
- Spike
- Posts: 2892
- Joined: Fri Nov 05, 2004 3:12 am
- Location: UK
You can change a float anywhere within it's scope as long as you didn't initialize it when you declared it.
In C++, you'd declare a constant by using the keyword "const" but in QuakeC just initializing a variable makes it a constant that cannot be changed.
In C++, you'd declare a constant by using the keyword "const" but in QuakeC just initializing a variable makes it a constant that cannot be changed.

-

DukeInstinct - Posts: 20
- Joined: Sat Jul 10, 2010 11:20 pm
- Location: DukeLand
DukeInstinct wrote:You can change a float anywhere within it's scope as long as you didn't initialize it when you declared it.
In C++, you'd declare a constant by using the keyword "const" but in QuakeC just initializing a variable makes it a constant that cannot be changed.
Also worth noting AFAIK you cannot initialize a local variable.
- GiffE
- Posts: 170
- Joined: Sun Oct 08, 2006 3:39 pm
- Location: USA, CT
7 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 1 guest