• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.
  • Create a faction for Warcraft 3 and enter Hive's 19th Techtree Contest: Co-Op Commanders! Click here to enter!
  • Create a void inspired texture for Warcraft 3 and enter Hive's 34th Texturing Contest: Void! Click here to enter!
  • The Hive's 21st Texturing Contest: Upgrade is now concluded, time to vote for your favourite set of icons! Click here to vote!

Questions about the use of "if"

Status
Not open for further replies.
Level 3
Joined
Aug 6, 2019
Messages
74
Does using more than one "if" in a function cause problems?
Here's the code:
[lua]
function UnitDeath(u)
u=GetTriggerUnit()
local id=GetUnitTypeId()

if id==FourCC("h000") then
Action1(u)
end

if id==FourCC("h001") then
Action2(u)
end

...

if id==FourCC("h060") then
Action60(u)
end

end
 
You can create a table that holds the functions beeing executed when an unit of UnitCode is killed. Inside an deathEvent check if you saved one for that unitCode and if there is execute it.
Could look like that, does not include Setting up the Event.
Lua:
do
    UnitDeathAction = {} --create the table
    UnitDeathAction[FourCC('Hpal')] = function(unit) --Setup an actionfunction for Paladin Units
        print("Paladin was killed")
    end
 
    function DeathEvent()
        local unit = GetTriggerUnit()
        local unitCode = GetUnitTypeId(unit)
        if UnitDeathAction[unitCode] then --is there a function for this unitCode?
            UnitDeathAction[unitCode](unit) --execute it and give the unit.
        end

    end

end
 
Last edited:
Status
Not open for further replies.
Top