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

[vJASS] Problem triggering events with real variables

Status
Not open for further replies.
Level 10
Joined
Sep 19, 2011
Messages
527
I solved, solution here

Thank you :).

Hi people, I came here because I have an strange problem triggering events with real variables :\.

The other days I was making a library (unit indexing type, and I know, there are a lot of systems right now), all works fine except for the events.

JASS:
library LUIS initializer Init
    globals
        // 1.00 = Index event
        // 2.00 = DeIndex event
        //real udg_LUIS_EVENT = 0.00
    
        private constant integer LEAVER_ABILITY = 'LUIS'
        
        private integer array recycle
        private integer recycleCount = 0
        
        private unit array units
        private integer count = 0
        
        /*private trigger onIndex = CreateTrigger()
        private trigger onDeIndex = CreateTrigger()*/
        
        private unit EVENT_UNIT = null
        
        // you will not die for another hashtable :3
        private hashtable ht = InitHashtable()
    endglobals
    
    function TriggerRegisterIndexEvent takes trigger t returns event
        return TriggerRegisterVariableEvent(t, "udg_LUIS_EVENT", EQUAL, 1.00)
    endfunction
    
    function TriggerRegisterDeIndexEvent takes trigger t returns nothing
        call TriggerRegisterVariableEvent(t, "udg_LUIS_EVENT", EQUAL, 2.00)
    endfunction
    
    /*function RegisterIndexEvent takes code c returns nothing
        call TriggerAddCondition(onIndex, Filter(c))
        call TriggerAddAction(onIndex, c)
    endfunction*/
    
    function GetIndexedUnit takes nothing returns unit
        return EVENT_UNIT
    endfunction
    
    function GetDeIndexedUnit takes nothing returns unit
        return EVENT_UNIT
    endfunction
    
    function GetUnitId takes unit u returns integer
        return LoadInteger(ht, GetHandleId(u), 0)
    endfunction
    
    function GetUnitById takes integer i returns unit
        return units[i]
    endfunction
    
    function LockUnit takes unit u, boolean b returns nothing
        call SaveBoolean(ht, GetHandleId(u), 1, b)
    endfunction
    
    function IsUnitIndexed takes unit u returns boolean
        return HaveSavedInteger(ht, GetHandleId(u), 0)
    endfunction
    
    function IsUnitLocked takes unit u returns boolean
        return LoadBoolean(ht, GetHandleId(u), 1)
    endfunction
    
    private function IndexUnit takes unit u returns nothing
        local integer i
        
        if (IsUnitIndexed(u) == false and IsUnitLocked(u) == false) then
            if (recycleCount == 0) then
                set count = count + 1
                set i = count
            else
                set i = recycle[recycleCount]
                set recycleCount = recycleCount - 1
            endif
            
            call SaveInteger(ht, GetHandleId(u), 0, i)
            call LockUnit(u, false)
            
            call UnitAddAbility(u, LEAVER_ABILITY)
            call UnitMakeAbilityPermanent(u, true, LEAVER_ABILITY)
            
            set EVENT_UNIT = u
            set udg_LUIS_EVENT = 1.00
            set udg_LUIS_EVENT = 0.00
            set EVENT_UNIT = null
        endif
    endfunction
    
    private function DeIndexUnit takes unit u returns nothing
        local integer handleId
        local integer id
    
        if (GetUnitAbilityLevel(u, LEAVER_ABILITY) == 0 and IsUnitIndexed(u)) then
            set handleId = GetHandleId(u)
            set id = GetUnitId(u)
            
            set recycleCount = recycleCount + 1
            set recycle[recycleCount] = id
            
            set units[id] = null
        
            set EVENT_UNIT = u
            set udg_LUIS_EVENT = 1.00
            set udg_LUIS_EVENT = 0.00
            set EVENT_UNIT = null
            
            call SaveInteger(ht, handleId, 0, 0)
            call RemoveSavedInteger(ht, handleId, 0)
            
            call SaveBoolean(ht, handleId, 1, false)
            call RemoveSavedBoolean(ht, handleId, 1)
        endif
    endfunction
    
    private function OnEnter takes nothing returns boolean
        call IndexUnit(GetFilterUnit())
        return false
    endfunction
    
    private function OnLeave takes nothing returns boolean
        call DeIndexUnit(GetFilterUnit())
        return false
    endfunction
    
    private function Init takes nothing returns nothing
        local integer i = bj_MAX_PLAYERS
        local trigger t = CreateTrigger()
        local boolexpr oL = Condition(function OnLeave)
        local region r = CreateRegion()
        local player p
        local unit u
        
        loop
            exitwhen i < 0
            
            set p = Player(i)
            
            call TriggerRegisterPlayerUnitEvent(t, p, EVENT_PLAYER_UNIT_ISSUED_ORDER, oL)
            call SetPlayerAbilityAvailable(p, LEAVER_ABILITY, false)
            
            call GroupEnumUnitsOfPlayer(bj_lastCreatedGroup, p, null)
            
            loop
                set u = FirstOfGroup(bj_lastCreatedGroup)
                exitwhen u == null
                call GroupRemoveUnit(bj_lastCreatedGroup, u)
                
                call IndexUnit(u)
            endloop
            
            set i = i - 1
        endloop
        
        call RegionAddRect(r, GetWorldBounds())
        call TriggerRegisterEnterRegion(CreateTrigger(), r, Condition(function OnEnter))
        
        set t = null
        set oL = null
        set r = null
        set p = null
    endfunction
endlibrary

As I say, no error unless we get here:

JASS:
set udg_LUIS_EVENT = 1.00
set udg_LUIS_EVENT = 0.00

Triggers that have the event:

JASS:
TriggerRegisterVariableEvent(t, "udg_LUIS_EVENT", EQUAL, 1.00)

Doesn't fire :\.

I was checking, dropping BJDebugMsg like a crazy man, but I can't find the failure.

If anyone can help me I would be very grateful. I will continue checking.

Greetings and thanks.
 
Last edited:
Level 10
Joined
Sep 19, 2011
Messages
527
Show an example where u use TriggerRegisterVariableEvent

Well I try both, GUI and JASS:

  • Untitled Trigger 001
    • Events
      • Game - LUIS_EVENT becomes Equal to 1.00
    • Conditions
    • Actions
      • Game - Display to (All players) the text: asd
JASS:
function test takes nothing returns nothing
    call BJDebugMsg("hi")
endfunction

//===========================================================================
function InitTrig_Untitled_Trigger_001 takes nothing returns nothing
    local trigger t = CreateTrigger()
    
    call TriggerRegisterVariableEvent(t, "udg_LUIS_EVENT", EQUAL, 1.00)
    call TriggerAddAction(t, function test)
    
    set t = null
endfunction

Greetings and thanks for your time.
 
Level 19
Joined
Aug 8, 2007
Messages
2,765
are you sure your updating LUIS_EVENT properly?

(meaning if u put a debug after setting LUIS_EVENT than print it out, it would print 1.00 than 0.00 than nothing because the other test functions dont run)
 
Level 10
Joined
Sep 19, 2011
Messages
527
just put debug messages in all of your conditions and see which condition is not firing then look whats causing it

Is what I'm doing :\.

are you sure your updating LUIS_EVENT properly?

(meaning if u put a debug after setting LUIS_EVENT than print it out, it would print 1.00 than 0.00 than nothing because the other test functions dont run)

I don't understand you.

The thing is, that this doesn't work even if I change the detonation event. I try adding conditions to the main triggers (onIndex, onDeIndex), then calling to TriggerEvaluate but still nothing :\.

Greetings and thanks.
 
Level 19
Joined
Aug 8, 2007
Messages
2,765
put a debug before you set LUIS_EVENT than put one after u set LUIS_EVENT both printing LUIS_EVENT
 
Level 10
Joined
Sep 19, 2011
Messages
527
Seems like the problem is that LUIS is running first than the other triggers.

EDIT: Well, as I said, the problem was that, the trigger execution order.

How I fix it?, with a timer:

JASS:
private function PreloaderRun takes nothing returns nothing
    local group g = CreateGroup()
        
    call GroupEnumUnitsOfPlayer(g, GetLocalPlayer(), Condition(function Check))
        
    call DestroyGroup(g)
    set g = null
        
    call DestroyTimer(GetExpiredTimer())
endfunction
        
private function Init takes nothing returns nothing
    call TimerStart(CreateTimer(), 0, false, function PreloaderRun)
endfunction

Thanks to everyone :)!.
 
Status
Not open for further replies.
Top