Flag field

From GTAModding
Jump to: navigation, search

A flag field is a decimal value representing a sequence of binary bits, each called a flag. A single flag has two possible states, either 0 or 1. It allows for representing multiple data in a single number. Examples of its usage in GTA are the object flags in the item definition file, CULL flags in the item placement file, and opcode 03F1 in the main.scm file.

Converting values

A reliable tool to convert the decimal value to a sequence of bits and back is Microsoft's Calculator in "Programmer" mode (or "Scientific" mode for older versions).

Using the object flags as an example, let's say you want your object to have the following properties: not fade when loading and allow transparencies of other objects. The binary value to not fade when loading is "10" and to allow transparencies of other objects is "100". "10" means, reading from right to left, the zeroth bit is off, the first bit is on, and the rest are off. "100" means the zeroth and first bits are off, the second bit is on, and the rest are off. To combine these two properties, add the two up and you get "110", having both the first and second bit on. Go to Calculator and you see a group of three-letter words: "Hex, Dec, Oct, Bin". Select "Bin" for binary. Type in your value "110" into the calculator. Now select "Dec" for decimal and it will show "6". This is the value to use as your object flag in the IDE file. Notice that "6" can also be obtained by adding "2" and "4" in decimal together.

In reverse, let's say you see an object in the game and want to find out what flags it has. You see "164" as a flag field being used on the object. As mentioned before, that number can be obtained by adding the decimal values up but it is very difficult to choose which decimal values add up to "164". Go to Calculator and select "Dec". Type in "164". Now select "Bin" and you will see "10100100". The second, fifth, and seventh bits are on. You can look at the table and see what binary numbers add up to that and which flags are associated to which properties. Flags "10000000", "100000", and "100" are used for this object.

External link

Post.png GTAForums: Brief explanation of turning them into bits, by Barton Waterduck