• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[JASS] What the hell is wrong with it?!

Status
Not open for further replies.
Level 21
Joined
Dec 9, 2007
Messages
3,096
Guys, I've been making an I2Text algorithm and it doesn't freaking work!!!

I get no errors but it just keeps saying "two billions" when i test!

JASS:
globals
string space = " "
string line = "-"
string an = " and "
string array TEXT_NUMBER
endglobals

function InitTrig_Func takes nothing returns nothing
    set TEXT_NUMBER[0] = ""
    set TEXT_NUMBER[1] = "one"
    set TEXT_NUMBER[2] = "two"
    set TEXT_NUMBER[3] = "three"
    set TEXT_NUMBER[4] = "four"
    set TEXT_NUMBER[5] = "five"
    set TEXT_NUMBER[6] = "six"
    set TEXT_NUMBER[7] = "seven"
    set TEXT_NUMBER[8] = "eight"
    set TEXT_NUMBER[9] = "nine"
    set TEXT_NUMBER[10] = "ten"
    set TEXT_NUMBER[11] = "eleven"
    set TEXT_NUMBER[12] = "twelve"
    set TEXT_NUMBER[13] = "thirteen"
    set TEXT_NUMBER[14] = "fourteen"
    set TEXT_NUMBER[15] = "fifteen"
    set TEXT_NUMBER[16] = "sixteen"
    set TEXT_NUMBER[17] = "seventeen"
    set TEXT_NUMBER[18] = "eighteen"
    set TEXT_NUMBER[19] = "nineteen"
// -----------------------------------------
    set TEXT_NUMBER[20] = "twenty"
    set TEXT_NUMBER[30] = "thirty"
    set TEXT_NUMBER[40] = "fourty"
    set TEXT_NUMBER[50] = "fifty"
    set TEXT_NUMBER[60] = "sixty"
    set TEXT_NUMBER[70] = "seventy"
    set TEXT_NUMBER[80] = "eighty"
    set TEXT_NUMBER[90] = "ninety"
// -----------------------------------------
    set TEXT_NUMBER[100] = "hundred"
    set TEXT_NUMBER[101] = "hundreds"
    set TEXT_NUMBER[1000] = "thousand"
    set TEXT_NUMBER[1001] = "thousands"
    set TEXT_NUMBER[2000] = "million"
    set TEXT_NUMBER[2001] = "millions"
    set TEXT_NUMBER[3000] = "billion"
    set TEXT_NUMBER[3001] = "billions"
endfunction

function I2Text takes integer value returns string
    local string text = I2S(value)
    local integer length = StringLength(text)
    local integer array numba
    local integer count = 1
    
    local string ts
    local integer ti
    local boolean array bool
    
    local string result = " "
    
    loop
        exitwhen count == length 
            set numba[count] = S2I(SubString(text, count - 1, count))
        set count = count + 1
    endloop
            
    
    if length > 9 then
        if S2I(SubString(text, 0, length - 9)) >= 2 then
            set ts = SubString(text, 0, length - 9)
            set ti = StringLength(ts)
            if ti > 3 then
                return "THE LENGTH OF THE INTEGER TO BE CONVERTED TO TEXT IS TOO LONG. PLEASE USE A SHORTER INTEGER, LESS THAN OR EQUAL TO 12 DIGITS LENGTH."
            endif
        elseif S2I(SubString(text, 0, length - 9)) == 1 then
            set ts = SubString(text, 0, 1)
            set ti = 1
        endif
        if ti == 3 then
            if numba[1] == 1 then
                set result = result + TEXT_NUMBER[numba[1]] + TEXT_NUMBER[100]
            elseif numba[1] >= 1 then
                set result = result + TEXT_NUMBER[numba[1]] + TEXT_NUMBER[101]
            elseif numba[1] == 0 then
                set bool[1] = true
            endif
            if numba[2] == 1 then
                if bool[1] == true then
                    set result = result + TEXT_NUMBER[ ( numba[2] * 10 ) + numba[3] ]
                    set bool[1] = false
                else
                    set result = result + an + TEXT_NUMBER[ numba[2] * 10 ] + TEXT_NUMBER[ numba[3] ]
                endif
            elseif numba[2] >= 1 then
                if bool[1] == true then
                    set result = result + TEXT_NUMBER[numba[2] * 10] + line + TEXT_NUMBER[numba[3]]
                    set bool[1] = false
                else
                    set result = result + an + TEXT_NUMBER[numba[2] * 10] + line + TEXT_NUMBER[numba[3]]
                endif
            endif
        elseif ti == 2 then
            if numba[1] == 1 then
                set result = result + TEXT_NUMBER[ ( numba[1] * 10 ) + numba[2] ]
            elseif numba[1] >= 1 then
                if numba[2] != 0 then
                    set result = result + TEXT_NUMBER[numba[1] * 10] + line + TEXT_NUMBER[numba[2]]
                else
                    set result = result + TEXT_NUMBER[numba[1] * 10]
                endif
            elseif numba[1] == 0 then
                if numba[2] != 0 then
                    set result = result + TEXT_NUMBER[numba[2]]
                else
                    set bool[2] = true
                endif
            endif
        elseif ti == 1 then
            if numba[1] != 0 then
                set result = result + TEXT_NUMBER[numba[1]]
            else
                set bool[2] = true
            endif
        endif
        if bool[2] == false then
            set result = result + TEXT_NUMBER[3001]
        endif
    endif
    return result
endfunction

This is a Work In Progress script and it's far from complete.
Please do not complain about that.

It also seems to work only on 1.24b
 
Last edited:
Lol I gave a link to the same system on wc3c.

EDIT:
Something like this might be better than what you have:
JASS:
library GetIntName initializer Init
    globals
        private hashtable Hasht
        private integer Count = 0
    endglobals

    function GetIntName takes integer i returns string
        return LoadStr(Hasht, 0, i)
    endfunction
    
    private function make takes string name returns nothing
        call SaveStr(Hasht, 0, Count, name)
        set Count = Count + 1
    endfunction
    
    private function make10 takes string name returns nothing
        call make(name)
        call make(name + "-one")
        call make(name + "-two")
        call make(name + "-three")
        call make(name + "-four")
        call make(name + "-five")
        call make(name + "-six")
        call make(name + "-seven")
        call make(name + "-eight")
        call make(name + "-nine")
    endfunction
    
    private function make100 takes string name returns nothing
        call make(name)
        call make(name + " and one")
        call make(name + " and two")
        call make(name + " and three")
        call make(name + " and four")
        call make(name + " and five")
        call make(name + " and six")
        call make(name + " and seven")
        call make(name + " and eight")
        call make(name + " and nine")
        //================================
        call make(name + " and ten")
        call make(name + " and eleven")
        call make(name + " and twelve")
        call make(name + " and thirteen")
        call make(name + " and fourteen")
        call make(name + " and fifteen")
        call make(name + " and sixteen")
        call make(name + " and seventeen")
        call make(name + " and eighteen")
        call make(name + " and nineteen")
        //================================
        call make10(name + " and twenty")
        call make10(name + " and thirty")
        call make10(name + " and fourty")
        call make10(name + " and fifty")
        call make10(name + " and sixty")
        call make10(name + " and seventy")
        call make10(name + " and eighty")
        call make10(name + " and ninety")
    endfunction
    
    private function make1000 takes string name returns nothing
        call make100(name)
        call make100(name + " one hundred")
        call make100(name + " two hundred")
        call make100(name + " three hundred")
        call make100(name + " four hundred")
        call make100(name + " five hundred")
        call make100(name + " six hundred")
        call make100(name + " seven hundred")
        call make100(name + " eight hundred")
        call make100(name + " nine hundred")
    endfunction
    
    private function Init takes nothing returns nothing
        set Hasht = InitHashtable()
        //==============================
        call make("zero")
        call make("one")
        call make("two")
        call make("three")
        call make("four")
        call make("five")
        call make("six")
        call make("seven")
        call make("eight")
        call make("nine")
        //==============================
        call make("ten")
        call make("eleven")
        call make("twelve")
        call make("thirteen")
        call make("fourteen")
        call make("fifteen")
        call make("sixteen")
        call make("seventeen")
        call make("eighteen")
        call make("nineteen")
        //==============================
        call make10("twenty")
        call make10("thirty")
        call make10("fourty")
        call make10("fifty")
        call make10("sixty")
        call make10("seventy")
        call make10("eighty")
        call make10("ninety")
        //==============================
        call make100("one hundred")
        call make100("two hundred")
        call make100("three hundred")
        call make100("four hundred")
        call make100("five hundred")
        call make100("six hundred")
        call make100("seven hundred")
        call make100("eight hundred")
        call make100("nine hundred")
        //==============================
        call make1000("one thousand")
        call make1000("two thousand")
        call make1000("three thousand")
        call make1000("four thousand")
        call make1000("five thousand")
        call make1000("six thousand")
        call make1000("seven thousand")
        call make1000("eight thousand")
        call make1000("nine thousand")
        call make("ten thousand")
    endfunction
endlibrary
This currently goes up to 10000, but it wouldn't be so hard to make it go higher, would it?

It can go as high as the maximum integer in wc3, which is, I think, FFFF FFFF (hexadecimal), or 4,294,967,295 (decimal, AKA normal numbers).

That might crash the initialization, however, as it'd take too long. But still, when would you need anything higher than maybe 100000?
 
Last edited:
Status
Not open for further replies.
Top