The debug console and UNIDs

This is a moderated forum that collects tutorials, guides, and references for creating Transcendence extensions and scripts.
Post Reply
relanat
Militia Captain
Militia Captain
Posts: 586
Joined: Tue Nov 05, 2013 9:56 am

Tue Oct 02, 2018 6:44 am

From game version 1.8b3.3.

First off, you cannot use the &itArtificialPlasma; format for UNIDs in the debug console.
That format gives an error;

Code: Select all

(typGetProperty &itArtificialPlasma; 'name)
Line 1: Mismatched open parenthesis
However a workaround for this was provided not long ago (hat-tip to 0xABCDEF).

The 'unvEntity' function will convert UNIDs in that format (we'll call them ENTITY UNIDS for reasons explained further down) to decimal UNIDs which can be used in the debug console.

Code: Select all

(unvEntity "itArtificialPlasma")
16629
In this example '16629' is the decimal format UNID of artificial plasma. Note that this is exactly the same UNID but in a different format. It may be of help to think of it as being in a different language.

So to get the name of &itArtificialPlasma; in the debug console we would use one of these two examples;

Code: Select all

(typGetProperty (unvEntity "itArtificialPlasma") 'name)
case of artificial plasma
(typGetProperty 16629 'name)
case of artificial plasma
Importantly, note that the '&' and ';' from the ENTITY UNID aren't included inside the quotes when using 'unvEntity'. See the attached image. That code doesn't work and returns 'Nil".

Easy. But wait, there's more!
There is a third format for UNIDs as well. Hex UNIDs (short for hexadecimal UNIDs).
Hexadecimal can also be known as 'base 16' numbering. (Decimal is 'base 10').
Hex numbers have the format '0x00000000' and use the 'numbers' 0 to 10 and A to F. Yes, that's right, in hex numbering A, B, C, D, E and F are numbers. Search for an explanation on the web if you are not sure how this works.

There are two methods to find the hex UNID.
If you search the 'Transcendence_Source' folder for itArtificialPlasma you will find it in HumanSpaceVol1.xml.
The code is:

Code: Select all

<!ENTITY itArtificialPlasma		"0x0000405F">
Here's the reason for calling them ENTITY UNIDs. They could also be called human-readable UNIDs.
The ENTITY UNID is itArtificialPlasma and the hex UNID equivalent is 0x0000405F.

Or you can use a function called 'mathDecToHex' (supplied by NMS and so useful that it is now included in the game code).

Code: Select all

(mathDecToHex 16629)
0x405F
(typGetProperty 0x405F 'name)
case of artificial plasma
Note the contraction of the hex UNID from 0x0000405F to 0x405F. Same thing. The extra '0's aren't necessary but can help to avoid confusion.

So we have three different ways of saying the same thing.
ENTITY UNID - &itArtificialPlasma;
Decimal UNID - 16629
Hex UNID - 0x0000405F

You can use any of these formats when writing code and the computer will happily accept them. (it's only in the debug console that the ENTITY UNID won't work).
But why so many options?
Because we are humans, not machines. Computers love using base 16 and can run with only the hex UNID format.
But as humans we are used to reading names and using decimal numbers. So the other two formats are included for our convenience. 'itArtificialPlasma' is a lot easier to understand and remember than 0x0000405F.
Attachments
debug UNID use.JPG
debug UNID use.JPG (92.71 KiB) Viewed 36 times

Post Reply