Difference between revisions of "Flag field"

From GTAMods Wiki
Jump to navigation Jump to search
(started tutorial)
 
m
 
(3 intermediate revisions by the same user not shown)
Line 1: Line 1:
'''Binary to decimal conversion''' is useful when trying to use and understand most flags that GTA uses, like [[OBJS#Object_Flags|object flags]]. The files uses decimal values that can be obtained from binary values. A reliable tool to use is Microsoft's Calculator in scientific mode. This tutorial will be using object flags as an example.
+
A '''[[wikipedia:Flag field|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 [[OBJS#Object flags|object flags]] in the [[IDE|item definition]] file, [[CULL#Flags|CULL flags]] in the [[IPL|item placement]] file, and [[03F1|opcode 03F1]] in the [[main.scm]] file.
  
==Binary to decimal==
+
== Converting values ==
Let's say you want to have your object have a wet effect when it's raining and has an alpha transparency to it. The binary value for a wet effect is "1" and for alpha transparency is "100." Add the two up and you get "101." Go to Calculator and you see a row of three-letter words "Hex, Dec, Oct, Bin." Select "Bin" for binary. Type in your value "101" into the calculator. Now select "Dec" for decimal and it will show "5." This value is the value to use as your object flag in the IDE file. Notice that "5" can also be obtained by adding "1" and "4" together.
+
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).
  
==Decimal to binary==
+
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.
Let's say you see an object in the game and want to find out what flags does it has. You see "164" as a flag 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." You can look at the table and see what binary numbers add up to that. Flags "10000000", "100000", and "100" were used.
+
 
 +
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 ==
 +
{{GTAF|post|106678|1126960|Brief explanation of turning them into bits}}, by {{U|Barton Waterduck}}
  
 
[[Category:Tutorials]]
 
[[Category:Tutorials]]

Latest revision as of 19:30, 5 November 2016

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