• 🏆 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] A scary script

Status
Not open for further replies.
So I was coding a Simple Scrambler :
JASS:
function Scramble takes string s returns string
    local string ts
    local string s2 = ""
    local string s3 = ""
    local integer i = 0
    local integer sl= StringLength(s)
    local integer i2 = 0
    local boolean flag = true
    loop
        exitwhen i == 4
        loop
            exitwhen i2 == sl
            set ts = SubString(s, i2, i2 + 1)
            if flag then
                set s2 = s2 + ts
            else
                set s3 = s3 + ts
            endif
            set flag = not flag
            set i2 = i2 + 1
        endloop
        set s = s2 + s3
        set s2 = ""
        set s3 = ""
        set i2 = 0
        set i = i + 1
    endloop
    return s
endfunction

function Descramble takes string s returns string
    local string ts
    local string s2
    local string s3
    local integer sl = StringLength(s)
    local integer i = 0
    local integer i2 = 0
    local boolean flag = true
    local boolean isOdd = ModuloInteger(sl, 2) == 1
    local string final = s
    loop
        exitwhen i == 4
        if isOdd then
            set s2 = SubString(final, 0, sl - 1 / 2 + 1)
            set s3 = SubString(final, sl - 1 / 2 + 1, sl)
        else
            set s2 = SubString(final, 0, sl / 2)
            set s3 = SubString(final, sl / 2, sl)
        endif
        loop
            exitwhen i2 == sl
            if flag then
                set ts = SubString(s2, i2, i2 + 1)
            else
                set ts = SubString(s3, i2, i2 + 1)
            endif
            set s = s + ts
            set flag = not flag
        endloop
        set final = s
        set s = ""
        set i = i + 1
    endloop
    return final
endfunction

But it seems that Warcraft 3 can't load the map fully when tried to test or play the game. Anyone can solve this?
 
Level 26
Joined
Aug 18, 2009
Messages
4,097
JASS:
        loop
            exitwhen i2 == sl
            if flag then
                set ts = SubString(s2, i2, i2 + 1)
            else
                set ts = SubString(s3, i2, i2 + 1)
            endif
            set s = s + ts
            set flag = not flag
        endloop

The aborting condition can never be fulfilled from inside because neither i2 nor sl are modified.

1/2 is integer division, therefore equals to 0. Maybe you meant to put the subtraction in parentheses?
 

LeP

LeP

Level 13
Joined
Feb 13, 2008
Messages
539
vJASS inlines this line sl - 1 / 2 + 1 to this : (((sl - 1) / 2) + 1)
[...]

a) That's not inlining
b) That's wrong

Look at outputwar3map.j in the logs directory in your jngp folder.
It gets verbatim copied to sl - 1 / 2 + 1 and we all know */ bind tighter than +-.
So the above is just ((sl - (1/2)) + 1) or when evaluated sl + 1 which might not be the thing you want to archieve.
 
Status
Not open for further replies.
Top