• 🏆 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!

[Solved] Function Call Bugging in Map Header

Status
Not open for further replies.
Level 6
Joined
Oct 31, 2015
Messages
95
Hello again guys, I need help. This is the map header of my map, it contains the header script for: @Bribe's Spell System, Get Host (don't know the author), @Vexorian's SimError and @TriggerHappy's CodeGen. I've tried to call a function from CodeGen but it displayed "Expected Array Index" for 7 lines. I checked all variables with arrays the system uses and they're fine. Also I'm pretty much sure that I've pasted all content correctly (did it 3 times). I got the same problem with @Almia's TimedEffect. The test maps work well, something is going wrong during the import and I don't understand why. I know little about the map header but whenever I try to paste lots of code in there I get some error message. Any help will be much appreciated.

Code:
function RegisterSpellSystem takes integer abilId, code onEffect, code onLoop returns nothing
    set udg_Spell__Ability = abilId
    if onEffect != null then
        set udg_Spell__Trigger_OnEffect = CreateTrigger()
        call TriggerAddCondition(udg_Spell__Trigger_OnEffect, Filter(onEffect))
    endif
    if onLoop != null then
        set udg_Spell__Trigger_OnLoop = CreateTrigger()
        call TriggerAddCondition(udg_Spell__Trigger_OnLoop, Filter(onLoop))
    endif
    if gg_trg_Spell_System == null then
        call ExecuteFunc("InitTrig_Spell_System")
    endif
    call TriggerExecute(gg_trg_Spell_System)
endfunction

function GetHost takes nothing returns nothing
    local gamecache g = InitGameCache("Map.w3v")
    call StoreInteger ( g, "Map", "Host", GetPlayerId(GetLocalPlayer ())+1)
    call TriggerSyncStart ()
    call SyncStoredInteger ( g, "Map", "Host" )
    call TriggerSyncReady ()
    set udg_Host = Player( GetStoredInteger ( g, "Map", "Host" )-1)
    call FlushGameCache( g )
    set g = null
endfunction

// SimError by Vexorian at wc3c.net

// Modified version

function IRS_SimError takes player p, string s returns nothing
    local string msg = "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n|cffffcc00" + s + "|r"
    local sound error = CreateSoundFromLabel ("InterfaceError", false, false, false, 10, 10)

    if GetLocalPlayer() == p then
        call ClearTextMessages ()
        call DisplayTimedTextToPlayer (p, 0.52, 0.96, 2.00, msg)
        call StartSound (error)
    endif
endfunction

function IRS_SimNotify takes player p, string s returns nothing
    local string msg = "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n|cffffcc00" + s + "|r"
    local sound notify = CreateSoundFromLabel("Hint", false, false, false, 10, 10)

    if GetLocalPlayer() == p then
        call ClearTextMessages()
        call DisplayTimedTextToPlayer (p, 0.52, 0.96, 2.00, msg)
        call StartSound (notify)
    endif
endfunction


function CodeGen_SaveToDisk takes string loadcode, string filename returns nothing
    call PreloadGenClear()
    call PreloadGenStart()
    call Preload(loadcode)
    call PreloadGenEnd(filename)
    call ClearSelection()
endfunction

function CodeGen_Init takes nothing returns nothing
    local integer i = 1
    local integer b = udg_SaveLoad_Base
    local integer m = udg_SaveLoad_MaxValue
    loop
        exitwhen i >= udg_SaveLoad_MaxValue
        set udg_SaveLoad_Char[i] = SubString(udg_SaveLoad_Alphabet, i, i+1)
        set i = i + 1
    endloop
    set udg_SaveLoad_Alphabet = SubString(udg_SaveLoad_Alphabet, 0, 1) + SubString(udg_SaveLoad_Alphabet, m + 1, b)
    set udg_SaveLoad_Base     = b - m
endfunction

function CodeGen_ConvertItem takes integer id returns integer
    local integer i = 1
    loop
        exitwhen i > udg_SaveLoad_ItemCount
        if (id == udg_SaveLoad_Item[i]) then
            return i
        endif
        set i = i + 1
    endloop
    return 0
endfunction

function CodeGen_ConvertUnit takes integer id returns integer
    local integer i = 1
    loop
        exitwhen i > udg_SaveLoad_HeroCount
        if (id == udg_SaveLoad_Hero[i]) then
            return i
        endif
        set i = i + 1
    endloop
    return 0
endfunction

function CodeGen_Encode takes integer i returns string
    local integer b
    local string s = ""
   
    if i <= udg_SaveLoad_Base then
        return SubString(udg_SaveLoad_Alphabet, i, i + 1)
    endif
   
    loop
        exitwhen i <= 0
        set b = i - (i / udg_SaveLoad_Base) * udg_SaveLoad_Base
        set s = SubString(udg_SaveLoad_Alphabet, b, b + 1) + s
        set i = i / udg_SaveLoad_Base
    endloop
   
    return s
endfunction

function CodeGen_StrPos takes string s returns integer
    local integer i = 0
    loop
        exitwhen i > udg_SaveLoad_Base
        if s == SubString(udg_SaveLoad_Alphabet, i, i + 1) then
            return i
        endif
        set i = i + 1
    endloop
    return -1
endfunction

function CodeGen_Decode takes string s returns integer
    local integer a = 0
   
    loop
        exitwhen StringLength(s) == 1
        set a = a * udg_SaveLoad_Base + udg_SaveLoad_Base * CodeGen_StrPos(SubString(s, 0, 1))
        set s = SubString(s, 1, 99)
    endloop
   
    return a+CodeGen_StrPos(s)
endfunction

function CodeGen_StringChecksum takes string in returns integer
    local integer i = 0
    local integer l = StringLength(in)
    local integer t = 0
    local integer o = 0
    loop
        exitwhen i >= l
        set t = CodeGen_Decode(SubString(in, i, i + 1))
        set o = o + t
        set i = i + 1
    endloop
    return o
endfunction

function CodeGen_Color takes string char returns string
    local integer i = 0
    local integer l = StringLength(udg_SaveLoad_Full)
    local string x  = ""
    loop
        exitwhen i >= l
        set x = SubString(udg_SaveLoad_Full, i, i + 1)
        if char == x then
            if (x=="0" or S2I(x) > 0) then
                return udg_SaveLoad_Number + char + "|r"
            elseif StringCase(x, false) == x then
                return udg_SaveLoad_Lower + char + "|r"
            elseif StringCase(x, true) == x then
                return udg_SaveLoad_Upper + char + "|r"
            endif
        endif
        set i = i + 1
    endloop
    return char
endfunction

function CodeGen_Format takes string s returns string
    local integer i = 0
    local integer x = StringLength(s)
    local integer j = 1
    local string s2 = ""
   
    loop
        exitwhen i >= x
       
        set s2 = s2 + CodeGen_Color(SubString(s, i, i + 1))
       
        if (j >= udg_SaveLoad_HyphenSpace and i != (x-1)) then
            set j = 0
            set s2 = s2 + udg_SaveLoad_SeperationChar
        endif
       
        set j = j + 1
        set i = i + 1
    endloop
   
    return s2
endfunction

function CodeGen_Strip takes string s returns string
    local integer i  = 0
    local integer x  = StringLength(s)
    local string out = ""
    local string a   = ""
   
    loop
        exitwhen i >= x
        set a = SubString(s, i, i + 1)
        if (a != udg_SaveLoad_SeperationChar) then
            set out = out + a
        endif
        set i = i + 1
    endloop
   
    return out
endfunction

// yeeahh descriptive variables
function CodeGen_Load takes string s returns nothing
    local string str = CodeGen_Strip(s)
    local string tmp = ""
    local string c   = ""
    local integer x  = 0
    local integer i  = 1
    local integer l  = 0
    local integer j  = 1
    local integer f  = 0
    local boolean b  = true
   
    set udg_SaveLoad_Valid = false
   
    if (udg_SaveLoad_Security) then
        loop
            exitwhen i > 3
            if (CodeGen_Decode(SubString(str, 0, i)) == CodeGen_StringChecksum(SubString(str, i, 999))) then
                set udg_SaveLoad_Valid = true
                set str = SubString(str, i, 999)
                set i = 4
            endif
            set i = i + 1
        endloop
    endif
   
    if (not udg_SaveLoad_Valid) then
        set udg_SaveLoad_Error = "Invalid Code"
        return
    endif
   
    set i = 0
    set l = StringLength(str)
   
    if (udg_SaveLoad_CheckName) then
        set c = CodeGen_Encode(CodeGen_StringChecksum(GetPlayerName(GetTriggerPlayer())))
        set i = StringLength(c)
        if (c != SubString(str, l - i, i)) then
            set udg_SaveLoad_Valid = false
            set udg_SaveLoad_Error = "Wrong username"
            return
        endif
        set l = l - i
    endif
   
    set i = 0
   
    loop
        exitwhen i >= l
        set tmp = SubString(str, i, i + 1)
       
        set b = true
        set f = 0
        set j = 1
       
        loop
            exitwhen f >= (udg_SaveLoad_MaxValue)
            if (tmp == udg_SaveLoad_Char[f]) then
                set j = f + 2
                set udg_Load[x] = CodeGen_Decode(SubString(str, i + 1, i + (j)))
                set b = false
                set f = udg_SaveLoad_MaxValue
            endif
            set f = f + 1
        endloop
       
        if (b) then
            set udg_Load[x] = CodeGen_Decode(tmp)
        endif
       
        set i = i + j
        set x = x + 1
    endloop
   
    set udg_SaveLoad_Valid = true
endfunction

function CodeGen_Compile takes nothing returns string
    local integer i  = 0
    local integer j  = 0
    local string out = ""
    local string ln  = ""
    local string x   = ""

    loop
        exitwhen i > udg_SaveCount
        set x = CodeGen_Encode(udg_Save[i])
        set j = StringLength(x)

        if (j > 1) then
            set out = out + udg_SaveLoad_Char[j-1]
        endif
       
        set out = out + x
        set i = i + 1
    endloop

    if (udg_SaveLoad_CheckName) then
        set out = out + CodeGen_Encode(CodeGen_StringChecksum(GetPlayerName(GetTriggerPlayer())))
    endif
   
    if (udg_SaveLoad_Security) then
        set out = CodeGen_Encode(CodeGen_StringChecksum(out)) + out
    endif
   
    if udg_SaveLoad_SaveToDisk and GetLocalPlayer() == GetTriggerPlayer() then
        call CodeGen_SaveToDisk(out, udg_SaveLoad_Directory + "\\" + udg_SaveLoad_Filename)
    endif
               
    return CodeGen_Format(out)
endfunction
 
Level 6
Joined
Oct 31, 2015
Messages
95
Understood. I'm being forced to use Jass since I updated to 1.29.1 instead of waited for WEX to update to 1.29, big mistake. Unfortunately vanilla WE doesn't love vJass like the rest of us, so do you know any way to use vJass in 1.29.1 or a way to downgrade back to 1.29?
 
Level 6
Joined
Oct 31, 2015
Messages
95
Thank you guys I figured out what my problem was. It was pretty silly indeed but the previous issue with TimedEffect made me think the two events were related but seems that it was only coincidence. There is a variable in my map named Hero[] and CodeGen uses a demo variable named Hero (no array). That "Expected Array Index" was from my variable which had the same name of the other so the editor didn't pasted the new one from CodeGen. Thank you both for helping me and specially for Jampion's hint about WEX. I've tried to install it with 1.29.1 but it didn't worked for me but it's now working fine with 1.29.2 so thank you very much :D

Thread Solved.
 
Status
Not open for further replies.
Top