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

Function can run only one times

Status
Not open for further replies.
Level 11
Joined
Dec 3, 2011
Messages
366
JASS:
scope Test initializer Init

private function Init takes nothing returns nothing
    // WORKING
    call AddLightning("CLPB", false, 2000,2000, -2000, -2000)
    call GroupEnumUnitsInLine(ENUM_GROUP,2000,2000,-2000,-2000,200,null)
        loop
            set bj_lastCreatedUnit = FirstOfGroup(ENUM_GROUP)
            exitwhen bj_lastCreatedUnit==null
            call SetUnitVertexColor(bj_lastCreatedUnit, 255, 0, 0, 255)
            call GroupRemoveUnit(ENUM_GROUP,bj_lastCreatedUnit)
        endloop
    call TriggerSleepAction(3)
    // NOT WORKING
    call GroupEnumUnitsInLine(ENUM_GROUP,2000,2000,-2000,-2000,200,null)
        loop
            set bj_lastCreatedUnit = FirstOfGroup(ENUM_GROUP)
            exitwhen bj_lastCreatedUnit==null
            call SetUnitVertexColor(bj_lastCreatedUnit, 255, 255, 0, 255)
            call GroupRemoveUnit(ENUM_GROUP,bj_lastCreatedUnit)
        endloop
endfunction

endscope

Idk why func
JASS:
GroupEnumUnitsInLine
only work one times.

I put that func in General Func. I can't see anything goes wrong so I need your help :goblin_cry::goblin_cry:

This is the test map
View attachment Standard Plugin.w3x

P/s: SOLVED
 
Last edited:
Level 24
Joined
Aug 1, 2013
Messages
4,657
I wont suggest ExecuteFunc() because the map optimizer changes the names of the functions.
I dont know if it also changes the strings in ExecuteFunc() but last time I checked it didnt.

You could make a trigger that starts on map init or make a timer that would call the second GroupEnumUnits action.
 
I wont suggest ExecuteFunc() because the map optimizer changes the names of the functions.
I dont know if it also changes the strings in ExecuteFunc() but last time I checked it didnt.

You could make a trigger that starts on map init or make a timer that would call the second GroupEnumUnits action.
Map optimizer won't break ExecuteFunc() unless you use string concatenation (and this only if you have "compress names" ticked).

So as long as you input the function name as a complete string, it will work.

This will work with map optimizer regardless of settings:
JASS:
library creampie initializer init

function lolpatrol takes nothing returns nothing
endfunction

function init takes nothing returns nothing
     call ExecuteFunc("lolpatrol")
endfunction

endlibrary

This will break when using map optimizer and "compress names" is ticked:
JASS:
library creampie initializer init

function lolpatrol takes nothing returns nothing
endfunction

function init takes nothing returns nothing
     call ExecuteFunc("lol"+"patrol")
endfunction

endlibrary

However, you can just do this and always be on the safe side:

JASS:
library creampie initializer init

function lolpatrol takes nothing returns nothing
endfunction

function init takes nothing returns nothing
     local trigger t = CreateTrigger()
     call TriggerAddAction(t, function lolpatrol)
     call TriggerExecute(t)
     set t = null
endfunction

endlibrary
 
Status
Not open for further replies.
Top