1. Join other hivers in a friendly concept-art contest. The contestants have to create a genie coming out of its container. We wish you the best of luck!
    Dismiss Notice
  2. The Melee Mapping Contest #4: 2v2 - Results are out! Step by to congratulate the winners!
    Dismiss Notice
  3. We're hosting the 15th Mini-Mapping Contest with YouTuber Abelhawk! The contestants are to create a custom map that uses the hidden content within Warcraft 3 or is inspired by any of the many secrets within the game.
    Dismiss Notice
  4. The 20th iteration of the Terraining Contest is upon us! Join and create exquisite Water Structures for it.
    Dismiss Notice
  5. Check out the Staff job openings thread.
    Dismiss Notice

[JASS] Passing a boolexpr?

Discussion in 'Triggers & Scripts' started by loktar, Apr 11, 2019.

  1. loktar

    loktar

    Joined:
    Nov 2, 2004
    Messages:
    705
    Resources:
    24
    Models:
    2
    Icons:
    16
    Packs:
    1
    Tools:
    2
    Spells:
    2
    Tutorials:
    1
    Resources:
    24
    I have a function where I register a trigger event. I want to pass the filter to that function from somewhere else.

    Code (vJASS):

    function register takes code filter returns nothing
        local conditionfunc fltr = Condition(filter)
        call TriggerRegisterEnterRegion(trg, rgn, fltr)
        call DestroyCondition(fltr)
        set fltr = null
    endfunction

    call register(code filterFunc)
     


    I was wondering if there a better way to do this so i don't have to use a local variable in the function?
    Thanks =)
     
    Last edited: Apr 11, 2019
  2. PurgeandFire

    PurgeandFire

    Code Moderator

    Joined:
    Nov 11, 2006
    Messages:
    7,420
    Resources:
    18
    Icons:
    1
    Spells:
    4
    Tutorials:
    9
    JASS:
    4
    Resources:
    18
    Just do this:
    Code (vJASS):
    function register takes code filter returns nothing
        call TriggerRegisterEnterRegion(trg, rgn, Condition(filter))
    endfunction


    Condition
    is special in that it reuses the same condition if you pass in the same code function. So you don't actually have to do any memory management for it.
     
  3. loktar

    loktar

    Joined:
    Nov 2, 2004
    Messages:
    705
    Resources:
    24
    Models:
    2
    Icons:
    16
    Packs:
    1
    Tools:
    2
    Spells:
    2
    Tutorials:
    1
    Resources:
    24
    Ah, that's good to know. I'm actually using it in the same function for an enumerator as well though, so I guess using a local variable is still preferable over doing Condition(filter) twice?

    Edit: actually, I've changed my approach, no longer doing this.
     
    Last edited: Apr 11, 2019