FTEQCC Keywords

From FTE
Revision as of 05:13, 10 July 2015 by Spike (talk | contribs) (Type Modifiers)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Note: not all keywords are enabled by default. They can be enabled via the commandline with '-kFOO', or via '#pragma keyword enable FOO' from QC.

Basic Types

  • entity
  • float
  • int
  • integer: synonym for int
  • string
  • vector
  • __variant: Some weird type that should only be used in builtin definitions. These variables have no explicit type, and should be cast or assigned to some other type before use.

Complex Types

  • struct: like in C. Useful in arrays or with pointers.
  • union: special case of struct where all members occupy the same bit of memory. Useful for type punning but somewhat unsafe.
  • class: has similarities to C++, but only supports single inheritance.

Type Modifiers

  • const: Specifies that the variable will not be changed. Any initialiser must also be a const.
  • nosave: Marks the variable as unsuitable for saving to saved games. Does not prevent loading.
  • inline: Usable on functions. Causes fteqcc to attempt to inline the function.
  • ignore: Specifies that the variable is not relevant in the current module. This is expected to be hidden inside preprocessor. When used on a function, the entire function will be ignored. Any actual references outside referenced functions will generate an error.
  • strip: Synonym for ignore
  • shared: Marks the global as something that should be shared between multiple .dat files in the same VM. Only makes sense with FTE_MULTIPROGS. Typically you will want to use pointers instead due to the overhead when crossing .dat boundaries (which can become significant when you have many shared variables).
  • unused: 'unused' means that the variable is unused, you're aware that its unused, and you'd rather not know about all the warnings this results in. These variables may also be stripped (otherwise, use 'used' instead).
  • noref: Synonym for unused.
  • used: used means that the variable is expected by the engine in some way, even if the qc never refers to it.
  • static: At global scope, specifies that the variable should be visible only to the current .qc file. At local scope, specifies that the local should act as a global (providing persistance), but only be visible to the current function.
  • nonstatic: opposite of static. Useful only when '#pragma defaultstatic 1' was used.
  • extern: Specifies that the function should be imported from another progs (FTE_MULTIPROGS).
  • var: Specifies that the variable should NOT be considered a constant. On fields, this prevents auto-initialisation. On functions, this prevents errors about missing function bodies.
  • optional: Used on function arguments to specify that you can omit that argument. This typically means that it should only ever be used on builtins. fteetensions.qc makes gratutious use of this keyword, but it is not particuarly useful elsewhere.

Control Keywords

  • break: Jump out of the innermost while/until/for/loop/switch statement. Avoids the 'increment' part of for loops.
  • continue: Jump back to the start of the innermost while/until/for/loop statement. The 'increment' part of for loops will be executed before the loop resumes.
  • switch: Specifies that control should jump to relavant inner case statement, if possible.
  • case x: Control will jump to here from the containing switch statement if the switch expression evaluated to the same as the case's value. Note that you will want to terminate the previous case statement with a break statement in order to avoid fall-through. Case statements act somewhat like labels, and thus require a colon rather than a semi-colon.
  • case x..y: Specifies a range of values instead of a singlular descrete value. Otherwise acts like any other case.
  • default: Specifies the fallback of a switch statement in the event that no case statement provided a match (instead of skipping past the switch entirely).
  • goto: considered harmful.
  • for (initialisation; condition; increment) : much like while, but provides explicit space for an initialisation an increment expressions. The increment expression interacts with continue statements in a way not trivially reproducable with while loops. Also, programmers who know C-like languages tend to expect it to exist.
  • until: logical-not version of while
  • loop: acts like while(1), resulting in an infinite loop that requires the use of break or return to leave.

Other

  • enum: Provides a way to specify a list of constants which are implicitly 1 greater than the previous constant, starting at 0. You are able to explicitly set a value, but you will get warnings if any two constants within an enum have the same value.
  • enumflags: Acts like enum, but also requires that values are power-of-two (and will autoincrement to satisfy that).
  • asm: The following function / line is direct assembler.
  • state: should be followed by eg [$frame,func] as found in many monster think functions. This provides you a way to use it mid-function.
  • thinktime <interval>: sets self.nextthink to time+interval
  • typedef: Allows you to provide a more terse name for complex types.