Snippet GetIntName

Azlier

Old World Ghost
Reaction score
461
This snippet gives you the proper name of an integer below 100. Ex: 7 = "seven", 23 = "twenty three".

It just looks more polished for an NPC to say "Please, bring me seven chickens." rather than "Please, bring me 7 chickens." Best used with constant integers set at the top of your vJass quests and such. Works for GUI, too, though.

One function is available to you.
JASS:
function GetIntName takes integer i returns string


Yep, that's it. I'd have gone higher, but textmacros cannot be run from textmacros.

JASS:
library GetIntName initializer Init

//*****************
//*  0 - 100 pack *
//*****************

globals
    private string array Names
    private integer Count = 0
endglobals

constant function GetIntName takes integer i returns string
    return Names<i>
endfunction

//! textmacro IntName__Set takes NAME
    set Names[Count] = &quot;$NAME$&quot;
    set Count = Count + 1
//! endtextmacro

//! textmacro IntName__SetTens takes NAME
    set Names[Count] = &quot;$NAME$&quot;
    set Count = Count + 1
    set Names[Count] = &quot;$NAME$-one&quot;
    set Count = Count + 1
    set Names[Count] = &quot;$NAME$-two&quot;
    set Count = Count + 1
    set Names[Count] = &quot;$NAME$-three&quot;
    set Count = Count + 1
    set Names[Count] = &quot;$NAME$-four&quot;
    set Count = Count + 1
    set Names[Count] = &quot;$NAME$-five&quot;
    set Count = Count + 1
    set Names[Count] = &quot;$NAME$-six&quot;
    set Count = Count + 1
    set Names[Count] = &quot;$NAME$-seven&quot;
    set Count = Count + 1
    set Names[Count] = &quot;$NAME$-eight&quot;
    set Count = Count + 1
    set Names[Count] = &quot;$NAME$-nine&quot;
    set Count = Count + 1
//! endtextmacro

private function Init takes nothing returns nothing
    //! runtextmacro IntName__Set(&quot;zero&quot;)
    //! runtextmacro IntName__Set(&quot;one&quot;)
    //! runtextmacro IntName__Set(&quot;two&quot;)
    //! runtextmacro IntName__Set(&quot;three&quot;)
    //! runtextmacro IntName__Set(&quot;four&quot;)
    //! runtextmacro IntName__Set(&quot;five&quot;)
    //! runtextmacro IntName__Set(&quot;six&quot;)
    //! runtextmacro IntName__Set(&quot;seven&quot;)
    //! runtextmacro IntName__Set(&quot;eight&quot;)
    //! runtextmacro IntName__Set(&quot;nine&quot;)
    //! runtextmacro IntName__Set(&quot;ten&quot;)
    //! runtextmacro IntName__Set(&quot;eleven&quot;)
    //! runtextmacro IntName__Set(&quot;twelve&quot;)
    //! runtextmacro IntName__Set(&quot;thirteen&quot;)
    //! runtextmacro IntName__Set(&quot;fourteen&quot;)
    //! runtextmacro IntName__Set(&quot;fifteen&quot;)
    //! runtextmacro IntName__Set(&quot;sixteen&quot;)
    //! runtextmacro IntName__Set(&quot;seventeen&quot;)
    //! runtextmacro IntName__Set(&quot;eightteen&quot;)
    //! runtextmacro IntName__Set(&quot;nineteen&quot;)
    
    //! runtextmacro IntName__SetTens(&quot;twenty&quot;)
    //! runtextmacro IntName__SetTens(&quot;thirty&quot;)
    //! runtextmacro IntName__SetTens(&quot;forty&quot;)
    //! runtextmacro IntName__SetTens(&quot;fifty&quot;)
    //! runtextmacro IntName__SetTens(&quot;sixty&quot;)
    //! runtextmacro IntName__SetTens(&quot;seventy&quot;)
    //! runtextmacro IntName__SetTens(&quot;eighty&quot;)
    //! runtextmacro IntName__SetTens(&quot;ninety&quot;)
    
    //! runtextmacro IntName__Set(&quot;one hundred&quot;)
endfunction

endlibrary</i>
 

Azlier

Old World Ghost
Reaction score
461
>It just makes sense.

Perhaps, but since when has Azlier been known to care about sense?
 

SerraAvenger

Cuz I can
Reaction score
234
I would've done some modulo stuff I guess. Interesting implementation you got there, just awkward memory usage...
 

Jesus4Lyf

Good Idea™
Reaction score
397
Not useful in many occasions, but useful, nonetheless.
Dude! This means now you can attach to structs!
JASS:
globals
    integer array Data
endglobals
...
set Data[StringHash(GetIntName(struct))]=data
set data=Data[StringHash(GetIntName(struct))]

:D :D :D

(I WILL shoot anyone who actually uses this, of course...)
 

Romek

Super Moderator
Reaction score
963
Very silly, J4L.
Why not just use Data[integer(struct)]? :p

Anyway, I think this is very useful indeed.
Only 101 numbers though? :(

> //! runtextmacro IntName__Set("eightteen")
eightteen? You mean eighteen.

> Works for GUI, too, though.
Why the commas? o_O
 

Azlier

Old World Ghost
Reaction score
461
Technically, you only type out numbers less than 12 in English anyway. I'd actually have gone to 500, but you can't run textmacros from textmacros :(.
 

Jesus4Lyf

Good Idea™
Reaction score
397
>Why not just use Data[integer(struct)]?
Because two separate structs with the same index would overwrite the value (same as in my method). The real question is why not just use fields? :D

>Why the commas? o_O
This soooo isn't the grammar zone. :p

On a serious note, make this return I2S for values that have no stored string version?
 

SerraAvenger

Cuz I can
Reaction score
234
On a related note, I'm so totally for
JASS:
constant function GetIntName takes integer i returns string
    if i &lt; 0 then
        return &quot;minus &quot; + GetIntName(-i)
    elseif Names<i> == null then
        return I2S( i )
    else
        return Names[ i ]
    endif    
endfunction
</i>
 

Romek

Super Moderator
Reaction score
963
I think 'negative' would sound better than 'minus'.
 

Andrewgosu

The Silent Pandaren Helper
Reaction score
716
This would be more useful if you'd make some kind of algorithm which "constructs" the correct string dependant on the input number.

:eek:
 

uberfoop

~=Admiral Stukov=~
Reaction score
177
And took advantage of the fact that each 10^3 group reuses the same names (ie 13, 13,000, 13,000,000, etc...) to make the system increasable by 10^3 in domain however many times you like without much trouble.

:)
 

SerraAvenger

Cuz I can
Reaction score
234
rawcode hashing would be the absolutely wrong algorithm for this. Just hashtables are much better.

Should probably know:
Code:
[0] - zero   
[1] - one
[2] - two 
[3] - three 
[4] - four
[5] - five
[6] - six
[7] - seven
[8] - eight
[9] - nine
// * 10 * ( index - 8 ) 
[10] - twenty
[11] - thirty
[13] - fifty
// * 10 ^ ( index - 13 )
[14] - ten
[15] - hundred
[16] - thousand
[19] - million
[22] - billion

And then construct:
Code:
Construct
 - triple block 1
  - letter 1
  - letter 2
  - letter 3
 - triple block 2
  - letter 1
  - letter 2
  - letter 3
 - triple block 3
  - letter 1
  - letter 2
  - letter 3

// EG:
Construct ( 123456789 )
 - triple block 1: 789
  - letter 1: 7 -> seven [ hundred]
  - letter 2: 8 -> eight [y]
  - letter 3: 9 -> nine
 - triple block 2: 456 [ thousand] [and]
  - letter 1: 4 -> four [ hundred]
  - letter 2: 5 -> [fifty]
  - letter 3: 6 -> six
 - triple block 3: 123 [ million]
  - letter 1: 1 -> one [ hundred]
  - letter 2: 2 -> [twenty]
  - letter 3: 3 -> three
-> one hundred twenty three million four hundred fifty six thousand and seven hundred eighty nine
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top