HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

String to integer problem

12-21-2009, 10:20 AM#1
Anachron
Sup!

Collapse JASS:
local string test = "'hpea'"
local integer id = S2I(test)
call BJDebugMsg(I2S(id))

Why doesn't this work? I need to convert the integer from the string to an object ID.
12-21-2009, 10:26 AM#2
Toadcop
lol... maybe should S2I also conver 0xff ? (hexademical)

you need to write own algorithm (function) to convert raw to decimal. i have done this with a preprocessor.
12-21-2009, 10:51 AM#3
Fledermaus
Because 'hpea' isn't a string, it's an integer. just display I2S('hpea')
12-21-2009, 11:01 AM#4
Anachron
Toadcoap, could you help me?
I need to generate IDs out of a string.

For example:
"'hpea', 'Hpal'" should return 2 integers, 'hpea' and 'Hpal'.
12-21-2009, 05:09 PM#5
TriggerHappy
Requires ASCII.

Collapse JASS:
    function String2Rawcode takes string s returns integer
        local integer i = StringLength(s)
        local integer j = 1
        local integer k = 0
        loop
            exitwhen i == 0
            set i = i-1
            set k = k+Char2Ascii(SubString(s, i, i+1))*j
            set j = j*256
        endloop
        return k
    endfunction
    function blah takes nothing returns nothing
        local string test = "'hpea'"
        local integer id = String2Rawcode(test)
        call BJDebugMsg(I2S(id))
    endfunction
12-21-2009, 05:33 PM#6
Rising_Dusk
Quote:
Originally Posted by Anachron
"'hpea', 'Hpal'" should return 2 integers, 'hpea' and 'Hpal'.
You mean "hpea" and "hpal". If you really need this (you really don't, but you can pretend that you do), then you will need the thing Trig posted in some form.
12-21-2009, 05:38 PM#7
Alevice
Quote:
Originally Posted by Anachron
Toadcoap, could you help me?
I need to generate IDs out of a string.

For example:
"'hpea', 'Hpal'" should return 2 integers, 'hpea' and 'Hpal'.


unfortunately for you string to integer only seems to parse number in decimnal notation. i dont recall if i testd it, but its likely "010" would retrun 10 rather than 8
01-04-2010, 09:15 AM#8
Anachron
But is 'Hpal' exactly the same as the integer of the 'Hpal' id? Is is threated the same way? Because I would need this CreateItem(ID, 0., 0.) with a parsed string.
01-04-2010, 10:10 AM#9
DioD
you can enter integer as decimal hex or raw BUT game process decimal only.