• 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.

[vJASS] Lag problem

Status
Not open for further replies.
Level 3
Joined
Apr 21, 2012
Messages
33
JASS:
scope FetalBody initializer init
    
    private function True takes nothing returns boolean
        return true
    endfunction
    
    private function condition takes nothing returns boolean
        return GetRandomInt(0, 100) <= 15 and IsPlayerEnemy(GetOwningPlayer(GetTriggerUnit()), GetOwningPlayer(GetAttacker())) and GetUnitAbilityLevel(GetTriggerUnit(), 'A004') > 0
    endfunction
    
    private function action takes nothing returns nothing
        local unit me = GetTriggerUnit()
        local unit dum = CreateUnit(GetOwningPlayer(me), 'h001', GetUnitX(me), GetUnitY(me), 180.0)
        call UnitAddAbility(dum, 'A003')
        call SetUnitAbilityLevel(dum, 'A003', GetUnitAbilityLevel( me, 'A004'))
        call IssueImmediateOrder(dum, "fanofknives")
        call KillUnit(dum)
        set dum = null
        set me = null
    endfunction
    
    private function init takes nothing returns nothing
        local trigger t = CreateTrigger()
        local integer i = 0
        loop
            exitwhen i>15
            call TriggerRegisterPlayerUnitEvent(t, Player(i), EVENT_PLAYER_UNIT_ATTACKED, Filter(function True))
        endloop
        call TriggerAddCondition( t, Condition(function condition))
        call TriggerAddAction(t, function action)
    endfunction
endscope

The code above is what I try to create an passice ability that if unit that has this ability has been attacked, i will has 15% chance to deal damage to enemy around.(use custom fan of knives) but when I test I find it lag everytime I got attacked. I just in process of practicing so may I ask what create that lag? Thanks.

EDIT: Sorry, This is solved.
 
Last edited:
Level 23
Joined
Apr 16, 2012
Messages
4,041
I dont see a reason for this to lagg more then once when not initialized. Maybe it has something to do with the order but I have worked with those before and it didnt lag.
Here is a little improvement of the code:

This will not make the code not lag(maybe) but will make it a little bit faster
Instead of using triggeraction you can use triggercondition for your actions, you cant use TriggerSleepAction tho.
Also function TriggerRegister... doesnt need to have filter in it, you can go with null.
Also you didnt null local trigger at the end of init function.

Also this is very abusable, If I rapidly press right click to attack and stop I will be dead in no time, you should use Damage Detection System or write your own(not recommanded tho)

JASS:
scope FetalBody initializer init
    
    private function action takes nothing returns nothing
        local unit me = GetTriggerUnit()
        local unit dum
        if GetRandomInt(0, 100) <= 15 and IsPlayerEnemy(GetOwningPlayer(GetTriggerUnit()), GetOwningPlayer(GetAttacker())) and GetUnitAbilityLevel(GetTriggerUnit(), 'A004') > 0 then
            set dum =  CreateUnit(GetOwningPlayer(me), 'h001', GetUnitX(me), GetUnitY(me), 180.0)
            call UnitAddAbility(dum, 'A003')
            call SetUnitAbilityLevel(dum, 'A003', GetUnitAbilityLevel( me, 'A004'))
            call IssueImmediateOrder(dum, "fanofknives")
            call KillUnit(dum)
        endif
        set dum = null
        set me = null
    endfunction
    
    private function init takes nothing returns nothing
        local trigger t = CreateTrigger()
        local integer i = 0
        loop
            exitwhen i>15
            call TriggerRegisterPlayerUnitEvent(t, Player(i), EVENT_PLAYER_UNIT_ATTACKED, null)
        endloop
        call TriggerAddCondition( t, Condition(function action))
        set t = null
    endfunction
endscope
 
Level 3
Joined
Apr 21, 2012
Messages
33
Thanks, but I already fixed that. For some reason when I remove the loop register in init function and instead add TriggerRegisterAnyUnitEventBJ, the lag all gone. I still don't understand why, but it seems that is the problem.

EDIT: And I also heard that passing null as BoolExpr will leak, or I misunderstood?
 
Level 23
Joined
Apr 16, 2012
Messages
4,041
ow I made mistake, action must return boolean of type false :D
It used to leak but they fixed it, null boolexpr is false I believe but I may be wrong
and yes that was the reason but I totally overllok it :D
it lagged because for player red it executed the action function like 4000 times :D
 
Status
Not open for further replies.
Top