• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[JASS] I2S without natives for use in AI scripts

I2S doesn't work in AI scripts. I used ChatGPT to create this replacement function that does the same thing as I2S, but without using the actual native.

JASS:
function I2C2 takes integer i returns string
    if i == 0 then
        return "0"
    elseif i == 1 then
        return "1"
    elseif i == 2 then
        return "2"
    elseif i == 3 then
        return "3"
    elseif i == 4 then
        return "4"
    elseif i == 5 then
        return "5"
    elseif i == 6 then
        return "6"
    elseif i == 7 then
        return "7"
    elseif i == 8 then
        return "8"
    elseif i == 9 then
        return "9"
    endif
    return ""
endfunction

function I2S2 takes integer i returns string
    local integer j = i
    local string s = ""
    local integer k = 0
    local boolean is_negative = false
    local integer MAX_DIGITS = 20
    if i < 0 then
        set is_negative = true
        set j = -j
    endif
    loop
        set s = I2C2(j - (j / 10) * 10) + s
        set j = j / 10
        set k = k + 1
        exitwhen j == 0 or k >= MAX_DIGITS
    endloop
    if is_negative then
        set s = "-" + s
    endif
    return s
endfunction
 
Last edited:
Blizzard's ancient Spaghetti seems to still haunt us to this day. Looks good to me, if what you say about I2S not working in AI is true. Approved. Kudos to you and to the AI.
Originally, I thought it didn't work because the integer was null or because of some other stupid problem, but then I found this: [JASS] - I2S does not work in AI script

And followed Retera's advice about implementing my own I2S function.
 
Top