Warcraft III resources & community, 2003–2006 · archived

ForString

not rated
Submitted by KaTTaNaText Parsing0 downloads
Works kind of like ForGroup or ForForce. Runs the code callback for each part of the string. Use the function GetEnumString() to refer to the currently picked string-chunk. The size of each part of the string is determined by chunkSize.
skipIncomplete determines wether to include the last part of the string, if that is not long enough to satisfy chunkSize.
For example:
ForString("The Jass Vault!", 2, , false) will run
8 times, where GetEnumString() will return respectively:
"Th", "e ", "Ja", "ss", " V", "au", "lt", "!"
If true were passed as the last argument, the "!" would have been skipped, and it would only have executed 7 times.

Source

function GetEnumString takes nothing returns string
    return bj_lastPlayedMusic
endfunction

function ForString takes string whichString, integer chunkSize, code callback, boolean skipIncomplete returns nothing
    local integer pos = 0
    local string chunk
    local integer size
    local string char
    local trigger exec = CreateTrigger()
    local boolean stop = false
    call TriggerAddAction(exec, callback)
    loop
        set size = 0
        set chunk = ""
        loop
            set char = SubString(whichString, pos+size, pos+1+size)
            set stop = (char == "")
            exitwhen stop or (size >= chunkSize)
            set size = size + 1
            set chunk = chunk + char
        endloop
        exitwhen stop
        set pos = pos + size
        set bj_lastPlayedMusic = chunk
        call TriggerExecute(exec)
    endloop
    if ( size > 0 ) and not skipIncomplete then
        set bj_lastPlayedMusic = SubString(whichString, pos, pos+size)
        call TriggerExecute(exec)
    endif
    call DestroyTrigger(exec)
endfunction

Comments

0

No comments.