Difference between revisions of "Display float in text"

From GTAMods Wiki
Jump to navigation Jump to search
(very useful)
 
m
 
(3 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 
[[Opcode|Opcodes]] can be used to display a [[GXT]] entry with numbers if the symbol ~1~ is present. It can only display integer values so any floating-point values will be displayed as an integer value instead. This code snippet converts float values with up to two decimal places into a format usable for all text with number support opcodes.
 
[[Opcode|Opcodes]] can be used to display a [[GXT]] entry with numbers if the symbol ~1~ is present. It can only display integer values so any floating-point values will be displayed as an integer value instead. This code snippet converts float values with up to two decimal places into a format usable for all text with number support opcodes.
  
First make sure your GXT entries can support at least two numbers. Get two GXT entries and have the numbers arranged in this format.
+
First make sure your GXT entries can support at least two numbers. Have your GXT entries inputted in this format.
 
  Key      Entry
 
  Key      Entry
 
  TEST    ~1~.~1~
 
  TEST    ~1~.~1~
 
  TEST0    ~1~.0~1~
 
  TEST0    ~1~.0~1~
 +
TESTN    -~1~.~1~
 +
TESTN0  -~1~.0~1~
  
Then get a floating-point value that you wish to display with a text. Use this code to convert the number into a readable text.
+
Have a floating-point value that you wish to print on the screen. Use this code to convert that number into a readable text.
 
<source lang="scm">
 
<source lang="scm">
 
//...
 
//...
0007: 0@ = 90.4                                       // your float value, example shown is 90.4
+
0007: 0@ = 90.4                 // your float value, example shown is 90.4
0092: 1@ = float 0@ to_integer                         // convert the original value to an integer, 90
+
0092: 1@ = float 0@ to_integer // convert the original value to an integer, 90
0093: 3@ = integer 1@ to_float                         // convert that value back to a float, 90.0
+
0093: 3@ = integer 1@ to_float // convert that value back to a float, 90.0
0087: 2@ = 0@                                         // get the original value so that original value is not lost, 90.4
+
0087: 2@ = 0@                   // get the original value so that original value is not lost, 90.4
0063: 2@ -= 3@                                         // subtract that value from the converted float, 90.4 - 90.0 = 0.4
+
0063: 2@ -= 3@                 // subtract that value from the converted float, 90.4 - 90.0 = 0.4
0013: 2@ *= 100.0                                     // multiply that value by a hundred, 0.4 * 100.0 = 40.0
+
0013: 2@ *= 100.0               // multiply that value by a hundred, 0.4 * 100.0 = 40.0
0092: 4@ = float 2@ to_integer                         // convert that value into an integer, 40
+
0092: 4@ = float 2@ to_integer // convert that value into an integer, 40
00D6: if
+
0095: make 4@ absolute_integer  // make value absolute
0019:  4@ > 9                                        // skip over values that have a zero in the first decimal place
+
if and
004D: jump_if_false @TextFloat
+
    // if original value is between -1.0 and 0.0
02FD: text_2numbers_lowpriority 'TEST' 1@ 4@ 100 ms 1 // use any opcodes that can support at least two numbers, 90.40
+
    0.0 > 0@
0002: jump @TextFloat2
+
    0@ > -1.0
 
+
then
:TextFloat
+
    if
02FD: text_2numbers_lowpriority 'TEST0' 1@ 4@ 100 ms 1 // if original value was 90.04, this will display it instead
+
        // if first decimal place of value is not zero
 
+
        4@ > 9
:TextFloat2
+
    then
 +
        // use any print text opcodes that can support at least two numbers
 +
        // if original value was -0.4, this will display it instead
 +
        02FD: text_2numbers_lowpriority 'TESTN' 1@ 4@ 1000 ms 1
 +
    else
 +
        // if original value was -0.04, this will display it instead
 +
        02FD: text_2numbers_lowpriority 'TESTN0' 1@ 4@ 1000 ms 1
 +
    end
 +
else
 +
    if
 +
        // if first decimal place of value is not zero
 +
        4@ > 9
 +
    then
 +
        // original value was 90.40, so this will display
 +
        02FD: text_2numbers_lowpriority 'TEST' 1@ 4@ 1000 ms 1
 +
    else
 +
        // if original value was 90.04, this will display it instead
 +
        02FD: text_2numbers_lowpriority 'TEST0' 1@ 4@ 1000 ms 1
 +
    end
 +
end
 
//...
 
//...
 
</source>
 
</source>
A more complex code is needed if you want to be more precise but the comments here should be enough to guide you. The most numbers one opcode can display separately is six ([[0308]]) but creativity can go a long way.
+
A more lengthy code is needed if you want to be more precise but the comments here should be enough to guide you. The most numbers one opcode can display separately is six ([[0308]]) but creativity can go a long way.
  
[[Category: Mission Scripting]]
+
== External links ==
 +
{{Icon|3}} {{GTAF|post|758692|1066814629}} &ndash; a [[CLEO]] script by {{U|Seemann}} displaying player coordinates as floats
 +
[[Category:Code Snippets]]

Latest revision as of 19:25, 1 June 2015

Opcodes can be used to display a GXT entry with numbers if the symbol ~1~ is present. It can only display integer values so any floating-point values will be displayed as an integer value instead. This code snippet converts float values with up to two decimal places into a format usable for all text with number support opcodes.

First make sure your GXT entries can support at least two numbers. Have your GXT entries inputted in this format.

Key      Entry
TEST     ~1~.~1~
TEST0    ~1~.0~1~
TESTN    -~1~.~1~
TESTN0   -~1~.0~1~

Have a floating-point value that you wish to print on the screen. Use this code to convert that number into a readable text.

//...
0007: 0@ = 90.4                 // your float value, example shown is 90.4
0092: 1@ = float 0@ to_integer  // convert the original value to an integer, 90
0093: 3@ = integer 1@ to_float  // convert that value back to a float, 90.0
0087: 2@ = 0@                   // get the original value so that original value is not lost, 90.4
0063: 2@ -= 3@                  // subtract that value from the converted float, 90.4 - 90.0 = 0.4
0013: 2@ *= 100.0               // multiply that value by a hundred, 0.4 * 100.0 = 40.0
0092: 4@ = float 2@ to_integer  // convert that value into an integer, 40
0095: make 4@ absolute_integer  // make value absolute
if and
    // if original value is between -1.0 and 0.0
    0.0 > 0@
    0@ > -1.0
then
    if
        // if first decimal place of value is not zero
        4@ > 9
    then
        // use any print text opcodes that can support at least two numbers
        // if original value was -0.4, this will display it instead
        02FD: text_2numbers_lowpriority 'TESTN' 1@ 4@ 1000 ms 1
    else
        // if original value was -0.04, this will display it instead
        02FD: text_2numbers_lowpriority 'TESTN0' 1@ 4@ 1000 ms 1
    end
else
    if
        // if first decimal place of value is not zero
        4@ > 9
    then
        // original value was 90.40, so this will display
        02FD: text_2numbers_lowpriority 'TEST' 1@ 4@ 1000 ms 1
    else
        // if original value was 90.04, this will display it instead
        02FD: text_2numbers_lowpriority 'TEST0' 1@ 4@ 1000 ms 1
    end
end
//...

A more lengthy code is needed if you want to be more precise but the comments here should be enough to guide you. The most numbers one opcode can display separately is six (0308) but creativity can go a long way.

External links

GTA III Post.png Post on GTAForums – a CLEO script by Seemann displaying player coordinates as floats