• Check out the results of the Techtree Contest #19!
  • 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 void inspired texture for Warcraft 3 and enter Hive's 34th Texturing Contest: Void! Click here to enter!
  • The Hive's 22nd Icon Contest: Creep Abilities is now concluded, time to vote for your favourite set of icons! Click here to vote!

[Lua] How to write normal trigger in LUA?

Status
Not open for further replies.
Level 35
Joined
Jun 11, 2017
Messages
1,222
Lua:
do
  local trigger = CreateTrigger()
  TriggerRegisterAnyUnitEventBJ(trigger, EVENT_UNIT_DEATH)
  TriggerAddCondition(trigger, Condition(function()
  end))
  TriggerAddAction(trigger, function()
    print("Works")
  end)
end


I have map only with that code. Why my map crashes to main screen and not loading?
Latest version of Reforged.
 
It's advised not to use a raw, unscoped do ... end in WC3 Lua because sometimes data declared there get garbage collected erroneously. Instead you should use something like this:
 
It's advised not to use a raw, unscoped do ... end in WC3 Lua because sometimes data declared there get garbage collected erroneously. Instead you should use something like this:
Thanks for advice.
As I undestood correctly, more proper version of my custom script should be next:

Lua:
do
 OnInit()
   local trigger = CreateTrigger()
   TriggerRegisterAnyUnitEventBJ(trigger, EVENT_UNIT_DEATH)
   TriggerAddCondition(trigger, Condition(function()
   end))
   TriggerAddAction(trigger, function()
     print("Works")
    end)
end
 
I don't even bother using Conditions in Lua. Just throw an If Then Else in your Action and filter things there, although maybe that's slower?
Lua:
do
 OnInit()

   local trigger = CreateTrigger()
   TriggerRegisterAnyUnitEventBJ(trigger, EVENT_UNIT_DEATH)

   TriggerAddAction(trigger, function()
       local u = GetTriggerUnit()
       if GetUnitLevel(u) <= 5 then
           print("it works")
       end
    end)

end
 
I don't even bother using Conditions in Lua. Just throw an If Then Else in your Action and filter things there, although maybe that's slower?
Lua:
do
 OnInit()
   local trigger = CreateTrigger()
   TriggerRegisterAnyUnitEventBJ(trigger, EVENT_UNIT_DEATH)

   TriggerAddAction(trigger, function()
       local u = GetTriggerUnit()
       if GetUnitLevel(u) <= 5 then
           print("it works")
       end
    end)
end
I agree with you, was trying to simulate standard GUI trigger in LUA, adding all fields (event, condition, action).
However I found where issue was - it was in event, which I used uncorrectly.
Event should be
Lua:
 EVENT_PLAYER_UNIT_DEATH
 
Status
Not open for further replies.
Back
Top