Index | FAQ | Search | Memberlist | Usergroups | Profile | Log in to check your private messages | Log in | Register

.float vs. float

| Inside3d Forums Forum Index -> QuakeC Programming

View previous topic :: View next topic
Author | Message
--- | ---
Mexicouger Joined: 01 May 2010 Posts: 129 |

Posted: Fri Jul 09, 2010 11:29 pm Post subject: .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?

Code:
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
_________________
Gosh... debby ryan Is hot. I swear I will mary her...
My project Prime for psp:
http://www.moddb.com/games/primepsp1
We have a website, But are getting a new one.

Back to top |

GiffE Joined: 08 Oct 2006 Posts: 141 Location: USA, CT |

Posted: Sat Jul 10, 2010 12:41 am Post subject: |

.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.
_________________
http://www.giffe-bin.net/

Back to top |

frag.machine Joined: 25 Nov 2006 Posts: 728 |

Posted: Sat Jul 10, 2010 12:54 am Post subject: |

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" ? ).
_________________
frag.machine - Q2K4 Project
http://fragmachine.quakedev.com/

Back to top |

Spike Joined: 05 Nov 2004 Posts: 944 Location: UK |

Posted: Sat Jul 10, 2010 7:02 am Post subject: |

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)
_________________
What's a signature?

Back to top |

DukeInstinct Joined: 10 Jul 2010 Posts: 4 Location: DukeLand |

Posted: Sun Jul 11, 2010 12:17 am Post subject: |

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.
_________________
Coder/3d modeler for UrbanWars

Back to top |

GiffE Joined: 08 Oct 2006 Posts: 141 Location: USA, CT |

Posted: Sun Jul 11, 2010 12:48 am Post subject: |

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.
_________________
http://www.giffe-bin.net/

Back to top |

Jukki Joined: 07 Apr 2010 Posts: 19 |

Posted: Sun Jul 11, 2010 4:42 pm Post subject: |

so can is his like .float needs entity (self,other etc) and float is like full games variable like rounds etc? Sry i am dump dont speak english

Back to top |

Display posts from previous:

| Inside3d Forums Forum Index -> QuakeC Programming | All times are GMT
Page 1 of 1

Jump to:

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

Powered by phpBB © 2004 phpBB Group