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: 8@ = get_int_from_ini_file "CarSpawnerRanges.ini" section "1" key "start"

It works, when parameter for section is string.

CODE
0AF0: 8@ = get_int_from_ini_file "CarSpawnerRanges.ini" section 7@ key "start"

My 7@ is integer.
Executing this code causes crash, so how can I convert integer variable 7@ to any other string e.g 13@

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 1@ 2@
 // 1@s will contain your value converted to string
end

:getPowVal
{
 Parameters:
   Passed:
     0@ - base
     1@ - exponent
   Result:
     2@ - integer/float

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

:getIntUnits
{
 Parameters:
   Passed:
     0@ - number
   Result:
     1@ - units -> 0 to 10

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

:getIntUnit
{
 Parameters:
   Passed:
     0@ - number
     1@ - unit position -> 0 to 10
   Result:
     0@ - unit

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

:convIntToStr
{
 Parameters:
   Passed:
     0@ - number -> -9999999 to 9999999
   Result:
     2@/3@ - string value

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

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