Quantcast

Jump to content

» «
Photo

How to convert integer variable to string?

2 replies to this topic
fastman92
  • fastman92

    фастман92 | ف

  • Members
  • Joined: 28 Jul 2009
  • Poland
  • Best Conversion 2016 [GTA: Underground] [Contribution]
    Contribution Award [Mods]

#1

Posted 04 October 2010 - 06:21 PM Edited by fastman92, 04 October 2010 - 06:32 PM.

CODE
0AF0: [email protected] = get_int_from_ini_file "CarSpawnerRanges.ini" section "1" key "start"

It works, when parameter for section is string.

CODE
0AF0: [email protected] = get_int_from_ini_file "CarSpawnerRanges.ini" section [email protected] key "start"

My [email protected] is integer.
Executing this code causes crash, so how can I convert integer variable [email protected] to any other string e.g [email protected]

Wesser
  • Wesser

    The complexity simplifier, the efficiency optimizer

  • Feroci
  • Joined: 19 Aug 2006
  • Unknown
  • Contribution Award [Mods]

#2

Posted 04 October 2010 - 06:51 PM

You have to make a lot of calculations to retrieve every integer unit and convert each one to string type. I've already done it since a while and it is a part of my CLEO3's SDK (still unreleased tounge2.gif):
CODE

{
 FUNCTIONS INCLUDED:

-   getPowVal
     Type: GET
       Description: Get the pow of an integer value.

-   getIntUnits
     Type: GET
       Description: Get all units of an integer value.

-   getIntUnit
     Type: GET
       Description: Get a specific unit of an integer value (from right).

-   convIntToStr
     Type: SET
       Description: Convert an integer value into a string.
}

{$CLEO}

0000: NOP

while true
 0AB1: call_scm_func @convIntToStr 1 num 65535 store_to [email protected] [email protected]
 // [email protected] will contain your value converted to string
end

:getPowVal
{
 Parameters:
   Passed:
     [email protected] - base
     [email protected] - exponent
   Result:
     [email protected] - integer/float

 Example:
   0AB1: call_scm_func @getPowVal 2 num 2 exp 3 store_to [email protected]
}
0085: [email protected] = [email protected]
if
 [email protected] > 0
then
 for [email protected] = 1 to [email protected]
   if
     [email protected] > 1
   then
     006A: [email protected] *= [email protected]
   end
 end
else
 if
   [email protected] < 0
 then
   0093: [email protected] = integer [email protected] to_float
   0093: [email protected] = integer [email protected] to_float
   for [email protected] = -1 to [email protected]
     if
       [email protected] < -1
     then
       006B: [email protected] *= [email protected]
     end
   end
   [email protected] = 1.0
   0073: [email protected] /= [email protected]
   0087: [email protected] = [email protected]
 else
   [email protected] = 1
 end
end
0AB2: ret 1 [email protected]

:getIntUnits
{
 Parameters:
   Passed:
     [email protected] - number
   Result:
     [email protected] - units -> 0 to 10

 Example:
   0AB1: call_scm_func @getIntUnits 1 num 125 store_to [email protected]
}
[email protected] = 0
0095: make [email protected] absolute_integer
if
 [email protected] <> 0
then
 while [email protected] > 0
   [email protected] /= 10
   [email protected] += 1
 end
else
 [email protected] = 1
end
0AB2: ret 1 [email protected]

:getIntUnit
{
 Parameters:
   Passed:
     [email protected] - number
     [email protected] - unit position -> 0 to 10
   Result:
     [email protected] - unit

 Example:
   0AB1: call_scm_func @getIntUnit 2 num 125 unit 2 store_to [email protected]
}
0095: make [email protected] absolute_integer
0AB1: call_scm_func @getIntUnits 1 num [email protected] store_to [email protected]
if
002D:  [email protected] >= [email protected]
then
 0085: [email protected] = [email protected]
 0AB1: call_scm_func @getPowVal 2 num 10 exp [email protected] store_to [email protected]
 0072: [email protected] /= [email protected]
 006A: [email protected] *= [email protected]
 0062: [email protected] -= [email protected]
 [email protected] -= 1
 0AB1: call_scm_func @getPowVal 2 num 10 exp [email protected] store_to [email protected]
 0072: [email protected] /= [email protected]
else
 [email protected] = 0
end
0AB2: ret 1 [email protected]

:convIntToStr
{
 Parameters:
   Passed:
     [email protected] - number -> -9999999 to 9999999
   Result:
     [email protected]/[email protected] - string value

 Example:
   0AB1: call_scm_func @convIntToStr 1 num 125 store_to [email protected] [email protected]
}
if and
 [email protected] <=  9999999
 [email protected] >= -9999999
then
 0AB1: call_scm_func @getIntUnits 1 num [email protected] store_to [email protected]
 if
   [email protected] > 7
 then
   [email protected] = 7
 end
 [email protected] = ''
 if
   [email protected] < 0
 then
   [email protected] = '-'
 end
 for [email protected] = [email protected] downto 1
   0AB1: call_scm_func @getIntUnit 2 num [email protected] unit [email protected] store_to [email protected]
   [email protected] += 0x30
   098B: [email protected] = [email protected] + [email protected]
 end
end
0AB2: ret 2 [email protected] [email protected]

fastman92
  • fastman92

    фастман92 | ف

  • Members
  • Joined: 28 Jul 2009
  • Poland
  • Best Conversion 2016 [GTA: Underground] [Contribution]
    Contribution Award [Mods]

#3

Posted 06 October 2010 - 06:21 PM

Thanks Wesser!
Your function(s) works perfectly.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users