Introduction

Expressions are used to compute complicated values from simpler ones. PCC can handle the usual arithmetic operators, as well as some more. The syntax used in PCC borrows much from BASIC, but also contains elements from C++ and Pascal.

PCC's values and variables are untyped, that is, they can contain values of any type. Unlike in typed languages, you don't have to declare a variable to have a particular type and are then bound to that.

 Numbers

PCC handles integers and real numbers. You can enter them as you are used to:

  1      integer, one
  1.0    real, one
  0.5    real, one half
  .5     ditto
  pi     built-in constant, real, π=3.14159265

Internally, PCC distinguishes between reals and integers, but you'll rarely notice that. The most prominent example is the exponentiation operator `^'. If you need to, you can use the Int() function to make an integer from a real number. Real numbers have a precision of about 7 digits, and can be at most ±10^39. Integers are 32 bit, and have a range of ca. ±2*10^9.

Numbers can be manipulated using the usual operators, see the operators page.

Note: some operators previously always yielded a real number, even if the result fit in an integer. Since version 1.1.17, PCC tries a bit harder to preserve "integerness" of a value: expressions like `2^4' or `256/2' now yield integers.

 Strings

Character strings (text) can be manipulated in various ways in PCC. String constants can be specified in two ways. With single quotes, everything up to the next single quote is considered content of the string:

  'This is a string'
  'String with "quotes" and \backslash'
  ''      % empty string

Inside a string delimited by double quotes, the backslash has a special meaning: "\t" is a tab character (can be used with {Listbox()}), "\n" is a newline (can be used with {MessageBox}), all other characters are taken literally.

  "This is a string"
  "String with \"quotes\" and \\backslash"
  ""   % empty string
  "Hello\nThere"

Strings can be concatenated (appended) using various operators, and substrings extracted using some functions.

Due to the way PCC is programmed, no string -- however you create it -- can exceed 255 characters. PCC2 has no such limit.

 Truth Values

Comparison operators yield a truth value (`boolean value', after a mathematician named Boole). You can also specify truth values directly using the `True' and `False' keywords.

Where PCC expects a truth value, it will also accept strings or numbers, where each non-zero number and each non-empty string is treated as `True', zeroes and empty strings as `False'. If PCC expects a numeric value where you specify a truth value, `True' turns into 1, and `False' turns into 0.

 EMPTY

A very special value is EMPTY. You get this value if you request a property which is not known, for example the friendly code of a visual contact. EMPTY has the convenient property of making most expressions EMPTY if one operand is EMPTY (some functions and operators except this rule). For example,

  Torp.LCount # " x " # Torp

is evaluated to a string like "10 x Mark 8 Photon" if the ship has torpedo launchers, but yields EMPTY (and thus disappears in printout) if not. I think this is much better than the alternative, which would be "0 x {unknown}".

To test if a value is EMPTY, use the IsEmpty function. You can not directly specify the EMPTY value, but if you really need to, you can use the idiom z(0).

When an empty value is passed to a command, the command behaves as if the parameter was not specified. If a mandatory parameter is EMPTY, the command is ignored. For example

  SetWarp speed

sets the specified warp speed, or does nothing when `speed' is EMPTY. Note that this only holds for built-in commands, it does not automatically apply to subroutines you write. You can easily add appropriate tests, of course:

  Sub DoSomething (a, Optional b)
    If IsEmpty(a) Then Return
    % ...
  EndSub

 Cargo Amounts

You often need to compute the total cost of something in minerals. Doing this mineral-by-mineral is cumbersome, that's why there are some functions to manipulate cargo sets. For example, the price of a Mark 8 torpedo is 1 kt of Tritanium, Molybdenum and Duranium, and 54 megacredits. In PCC, this cost can be represented as "1tdm 54$". The price of 13 torpedoes is then easily computed using `CMul("1tdm 54$", 13)'.

Such a cargo set consists of a sequence of numbers followed by units (cargo types). The following cargo types are defined:

n t d mThe four standard minerals
$Money (megacredits)
sSupplies
cColonist clans
fFighters
wTorpedoes

Like you see in the above example, you can attach multiple units to each number ("1tdm" is one kt Tritanium, one kt Duranium, and one kt Molybdenum). And, you can write multiple such blocks. Note that there must not be a space between the number and the units.

See also: Interpreter - Main, Operators, Properties, Functions


[ << Previous | Up | Next >> ]

Stefan Reuther <Streu@gmx.de>