Hosting and domain costs until October 2024 have been generously sponsored by dumptruck_ds. Thank you!

Editing QuakeC Simple Types

From Quake Wiki

Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.
Latest revision Your text
Line 1: Line 1:
 +
<H1><FONT COLOR="#007F00">2. The Quake-C Basic Types</FONT></H1>
  
== The simple Types ==
 
  
<h4>[[void]] type</h4>
+
<h2>2.1 The simple Types</h2>
 +
 
 +
<h4>2.1.1 Void type</h4>
  
 
<p>An empty result, mostly used for definition of procedures (i.e. functions  
 
<p>An empty result, mostly used for definition of procedures (i.e. functions  
Line 8: Line 10:
 
</p>
 
</p>
  
<h4>[[Float]] type</h4>
+
<h4>2.1.2 Float type</h4>
  
 
<p>A floating point value.</p>
 
<p>A floating point value.</p>
Line 24: Line 26:
 
</p>
 
</p>
  
<h4>[[Vector]] type</h4>
+
<h4>2.1.3 Vector type</h4>
  
<p>A vector, made of 3 float coordinates.
+
<p>A vector, made of 3 <a href="qc-types.htm#float" target="content">float</a> coordinates.
 
<br>
 
<br>
 
Used to represent positions or directions in 3D space.
 
Used to represent positions or directions in 3D space.
Line 43: Line 45:
 
</p>
 
</p>
  
<h4>[[String]] type</h4>
+
<h4>2.1.4 String type</h4>
  
 
<p>This is used to store character string.
 
<p>This is used to store character string.
Line 49: Line 51:
 
Used to indicate file names, or messages to be broadcast to players.
 
Used to indicate file names, or messages to be broadcast to players.
 
<br>
 
<br>
Valid syntax: <b>"maps/jrwiz1.bsp"</b> or <b>"ouch!\n"</b>
+
Valid syntax: <b>"maps/jrwiz1.bsp"</b> or <b>"ouch!\
 +
"</b>
  
 
<br>
 
<br>
Use <b>\n</b> for newline.
+
Use <b>\
 +
</b> for newline.
 
</p>
 
</p>
 
<p>Note: that character strings cannot be modified, or concatenated.
 
<p>Note: that character strings cannot be modified, or concatenated.
 
Because they are stored at fixed locations in memory, and if
 
Because they are stored at fixed locations in memory, and if
would be potentially troublesome to allow modification.
+
would be postentially troublesome to allow modification.
 
</p>
 
</p>
  
<h4>entity type</h4>
+
<h4>2.1.5 entity type</h4>
  
 
<p>The reference of an entity in the game, like things, players, monsters.<br>
 
<p>The reference of an entity in the game, like things, players, monsters.<br>
Line 69: Line 73:
 
A description of each field is available.
 
A description of each field is available.
 
</p>
 
</p>
 +
 +
 +
<hr>
 +
<h2>2.2 The field types</h2>
 +
 +
<h4>2.2.1 What's a field?</h4>
 +
 +
<p>Countrary to the other types, the [[entity]] type
 +
is a reference to an instance of a structured object, that contains
 +
many informations of totally different kinds.</p>
 +
 +
<p>To access all these informations conveniently, they are stored as
 +
fields of the entity object, and each field is given a name and a type,
 +
that makes it distinct of the others.</p>
 +
 +
<p>Some of the fields do not store value, but instead they store the
 +
function to be executed in certain conditions. They are called the
 +
<b>methods</b> that can be aplied to the object.</p>
 +
 +
<p>If Quake-C was an object oriented programming language, those method
 +
functions and would be distinguished from the other fields. And, above
 +
all, you would be able to create new object types, with their own fields.</p>
 +
 +
<p>As Quake-C stands currently, <b>all the field definitions</b> are
 +
definitions of entity fields. So anywhere in your code you could add
 +
definition of new fields, and the compiler would interpret them
 +
as an extension of the entity definition.</p>
 +
 +
 +
<h4>2.2.2 Creating new fields</h4>
 +
 +
<p>The only way to extend the <a href="qc-types.htm#entity" target="content">entity</a> type
 +
is to add some fields at the end of the structures.</p>
 +
 +
<p>This is done via a field definitions, whose general structure is:
 +
<pre>
 +
  <b>.<a href="qc-types.htm#QC-TSMP" target="content">type</a> field_name;</b>
 +
</pre>
 +
</p>
 +
 +
<p> For instance, if you wanted to add a sling to the game, and needed
 +
to store the count of pellets for every player, you would add
 +
the following line in the source code:
 +
<pre>
 +
  <b>.<a href="qc-types.htm#QC-TSMP" target="content">float</a> ammo_sling;</b>
 +
</pre>
 +
That will add a fields <b>ammo_sling</b> to every entity in the game,
 +
and in particular to the player entities.
 +
</p>
 +
 +
<p>Here are all the possible definitions of entity fields, with their <a href="qc-types.htm#QC-TSMP" target="content">types</a>:
 +
<pre>
 +
    <a name="dot_float">.float</a> <i>field_name</i>;
 +
    <a name="dot_string">.string</a> <i>field_name</i>;
 +
    <a name="dot_vector">.vector</a> <i>field_name</i>;
 +
    <a name="dot_entity">.entity</a> <i>field_name</i>;
 +
 +
</pre>
 +
</p>
 +
 +
<p>The strange bit is that you can add those type definitions almost
 +
anywhere in the source code. They are not supposed to be grouped in
 +
a single place, where the entity type would be defined.
 +
</p>
 +
 +
<h4>2.2.3 Allowed modifications of types</h4>
 +
 +
<p>In the first file read by the Quake-C compiler, <b>[[defs.qc]]</b>,
 +
there must be a definition for the entity fields, and world fields.
 +
This definition is hard coded. You had better not touch it,
 +
or you will have to recompile Quake itself.
 +
<p>
 +
 +
<p>The globals are defined before the special definition
 +
<b>[[void end_sys_globals;]]</b><br>
 +
 +
The entity fields are defined before the special
 +
definition <b>[[void end_sys_fields;]]</b></p>
 +
 +
<p>It's not important if you don't understand the nonsense
 +
above. It's an ugly hack. Just <b>don't modify defs.qc</b>
 +
before those two tags, and you won't be in trouble.</p>
 +
<hr>

Please note that all contributions to Quake Wiki are considered to be released under the GNU Free Documentation License 1.3 or later (see Quake Wiki:Copyrights for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource. Do not submit copyrighted work without permission!

To edit this page, please answer the question that appears below (more info):

Cancel | Editing help (opens in new window)