Jump to content

Rounding off variables


Recommended Posts

I'm not exactly a pro coder, but I like to do experiments here and there in SA just to sustain a general ability towards it.


What I need to know today is how to round off a variable. For example..


I have


0819: 1@ = actor $PLAYER_ACTOR distance_from_ground


And now I want to round this down to a whole number so I can have it displayed ingame at a certain point through a GXT text.


02FD: show_text_2numbers_lowpriority GXT 'PARCNT' numbers 1@ 32@ time 7000 flag 1


For interests sake, the script is to show how far above the ground a person deploys a parachute in SA, then how long they glide before touching down (Kind of like TBoGT).


Help is much appreciated smile.gif

Link to comment
Share on other sites

The main thing concerned here is the nation that SCM has to seperate types of values to represent a number: Floats and Integers.

Floats are numbers with a decimal dot in them, while Integers can only represent whole numbers.


Floats in SCM are mainly used for coordinates, distances and angles. The 0819 opcode you mention is an opcode that returns a float value and the 02FD opcode is able to display an integer value. The conversion between Float and Integers if quite often used in SCM, and therefor 8 opcodes are provided to do this conversion. One for each direction between any of the four possible combinations of local and global variables.


008C=2,%1d% = float_to_integer %2d%; global, global008D=2,%1d% = integer_to_float %2d%; global, global008E=2,%1d% = float_to_integer %2d%; local, global008F=2,%1d% = integer_to_float %2d%; local, global0090=2,%1d% = float_to_integer %2d%; global, local0091=2,%1d% = integer_to_float %2d%; global, local0092=2,%1d% = float_to_integer %2d%; local, local0093=2,%1d% = integer_to_float %2d%; local, local



Thus resulting in your case:


0819: 1@ = actor $PLAYER_ACTOR distance_from_ground0092: 2@ = float_to_integer 1@; local, local02FD: show_text_2numbers_lowpriority GXT 'PARCNT' numbers 2@ 32@ time 7000 flag 1


Link to comment
Share on other sites

Mate, you are a life saver. I was always wondering what the deal with floats and integers were (I know, it's basic stuff too), and now I know. Thanks heaps.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • 1 User Currently Viewing
    0 members, 0 Anonymous, 1 Guest

  • Create New...

Important Information

By using GTAForums.com, you agree to our Terms of Use and Privacy Policy.