• 🏆 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!
  • ✅ The POLL for Hive's Texturing Contest #33 is OPEN! Vote for the TOP 3 SKINS! 🔗Click here to cast your vote!

[vJASS] using boolexpr like triggers

Status
Not open for further replies.
Level 6
Joined
Oct 23, 2011
Messages
182
Is there any downside to using boolexpr like a trigger, instead of using actual trigger? boolexpr seems to use much less memory than creating a trigger.

The code below works just like Nestharus' Event library: pretty much same fps drop and op limit

JASS:
library SmallEvent

    private module M
        private static method onInit takes nothing returns nothing
            set runner = CreateForce()
            
            call ForceAddPlayer(runner, Player(0))
        endmethod
    endmodule
    struct SmallEvent extends array
        implement M
        
        boolexpr func
        
        private static force runner = null
        private static integer index = 0
        
        method fire takes nothing returns nothing
            call ForceEnumPlayers(runner, .func)
        endmethod
        
        method register takes code c returns nothing
            if .func == null then
                set .func = Filter(c)
            else
                set .func = Or(.func, Filter(c))
            endif
        endmethod
        static method create takes nothing returns thistype
            local thistype this = index + 1
            
            set index = this
            return this
        endmethod
    endstruct
    
endlibrary
 
The event library should let you unregister the event, otherwise it's just the same as adding some conditions to a trigger and evaluating it. This would be a revolutionary idea if it worked! Unfortunately, it bugs with multiple players and runs the event more than once. Enumerating depletes the force of any players, so when you think you're only enumerating that one player it enumerates all of them.

I made the RealEvent library which is the best of both worlds and is a super short script:

http://www.hiveworkshop.com/forums/submissions-414/snippet-realevent-270158/
 
Level 6
Joined
Oct 23, 2011
Messages
182
I'm not sure what you mean by 'Enumerating depletes the force of any players, so when you think you're only enumerating that one player it enumerates all of them.' so after enum, the force is depleted = empty?
 
Level 40
Joined
Dec 14, 2005
Messages
10,532
To answer the initial question, yes, there are two downsides of boolexprs:

The first, which is sort of trivial, is that it's annoying to return a meaningless boolean at the end of your function.

The second, which is more important, is that boolexprs aren't threaded properly (since they behave more like a function call) and some things (such as TriggerSleepAction) may not work the way you want them to.
 
Status
Not open for further replies.
Top