Home   Help Search Login Register  

Author Topic: [SOLVED] Splitting a number up to 3 variables  (Read 1494 times)

0 Members and 1 Guest are viewing this topic.

Offline JasonO

  • OFPEC Patron
  • ****
  • Oh no...
    • The New Life RPG
[SOLVED] Splitting a number up to 3 variables
« on: 24 Jun 2009, 02:35:52 »
Hi guys,

I have a number, and I want a seperate value for each number. I thought about dividing by 100, dividing by 10, etc, but wont always work :(

So, the number I have is 120. I want this so I can have it like this:

_var1 = 1;
_var2 = 2;
_var3 = 0;

For example. The number is the speed, and wont be used for anything other than land vehicle so 3 digits is enough

I'm really trying to learn SQF, and I was wondering if this is possible.

Thanks a lot (again!) for your help :)

Edit: I really have to stop posting here, THEN find a solution lol.

      
Code: [Select]
_num1 = _speedVar % 10;

_speedVar = _speedVar / 10;
_speedVar = _speedVar - (_speedVar mod 1);

_num2 = _speedVar % 10;

_speedVar = _speedVar / 10;
_speedVar = _speedVar - (_speedVar mod 1);

_num3 = _speedVar % 10;

_num1, _num2 and _num3 all hold the seperate values.
« Last Edit: 24 Jun 2009, 04:30:50 by JasonO »

Offline Spooner

  • Members
  • *
  • Mostly useless
    • Community Base Addons
Re: [SOLVED] Splitting a number up to 3 variables
« Reply #1 on: 25 Jun 2009, 02:02:01 »
Code: [Select]
_speedVar = _speedVar - (_speedVar mod 1);
// Can be written as:
_speedVar = floor _speedVar;
floor rounds a number down and ceil rounds a number up. Just shorter and more clear what you are doing.
[Arma 2] CBA: Community Base Addons
[Arma 1] SPON Core (including links to my other scripts)