System DoubleClick

Azlier

Old World Ghost
Reaction score
461
It detects when you click the same unit twice within the provided time (a second by default).

A single function is available to you.
JASS:
function TriggerRegisterDoubleClickEvent takes trigger whichTrigger returns nothing


DestroyTrigger friendly, leakless, uses no H2I or any attachment besides what is done at initialization.

Requires Event.

Your friend, Azlier. Oh, and I just found that Azlier is just Lazier jumbled up. Bah.

JASS:
library DoubleClick initializer Init requires Event


globals
    private constant real CLICK_THRESHHOLD = 1.
    //How much time between clicks it takes to register a double click.
endglobals

//** System Code **

globals
    private boolean array Clicking
    private unit array Clicked
    private timer array ClickTimer
    private Event Ev
    private trigger array ClickTrig
endglobals

private function SetTriggerData takes trigger t, integer i returns nothing
    loop
        exitwhen i == 0
        call TriggerExecute(t)
        set i = i - 1
    endloop
endfunction

function TriggerRegisterDoubleClickEvent takes trigger whichTrigger returns nothing
    call Ev.register(whichTrigger)
endfunction

private function Callback takes nothing returns boolean
    set Clicking[GetTriggerExecCount(GetTriggeringTrigger())] = false
    return false
endfunction

globals
    private integer Id
    private unit Cu
endglobals
    
private function Actions takes nothing returns boolean
    set Id = GetPlayerId(GetTriggerPlayer())
    set Cu = GetTriggerUnit()
    if Clicking[Id] then
        call PauseTimer(ClickTimer[Id])
        if Clicked[Id] == Cu then
            call Ev.fire()
            set Clicking[Id] = false
        else
            set Clicked[Id] = Cu
            call TimerStart(ClickTimer[Id], CLICK_THRESHHOLD, false, null)
        endif
    else
        set Clicking[Id] = true
        set Clicked[Id] = Cu
        call TimerStart(ClickTimer[Id], CLICK_THRESHHOLD, false, null)
    endif
    return false
endfunction

private function Init takes nothing returns nothing
    local trigger t = CreateTrigger()
    local integer i = 11
    set Ev = Event.create()
    call TriggerAddCondition(t, Condition(function Actions))
    loop
        exitwhen i < 0
        call TriggerRegisterPlayerUnitEvent(t, Player(i), EVENT_PLAYER_UNIT_SELECTED, null)
        set ClickTimer<i> = CreateTimer()
        set ClickTrig<i> = CreateTrigger()
        call SetTriggerData.execute(ClickTrig<i>, i)
        call TriggerRegisterTimerExpireEvent(ClickTrig<i>, ClickTimer<i>)
        call TriggerAddCondition(ClickTrig<i>, Condition(function Callback))
        set i = i - 1
    endloop
endfunction

endlibrary</i></i></i></i></i></i>
 

Attachments

  • DoubleClick.w3x
    23.6 KB · Views: 348

Builder Bob

Live free or don't
Reaction score
249
It looks very user friendly and efficient.

I just thought I'd mention that the struct member trig will not magically become null when the trigger it is pointing to has been destroyed. As far as I can see it will never become null.

JASS:
if .trig == null then
    //Did the user destroy the trigger? Well. 
    //Let&#039;s stitch the list together.
    set .next.prev = .prev
    set .prev.next = .next
    set .temp = this
    set this = .next
    call .temp.destroy()
else



Edit: [del]Using GetTriggerExecCount() as attached data looks functional. However, couldn't you just have used playerId of triggering player? I'm just wondering why you chose a more complex solution. No need to change anything for my sake anyway. It makes no difference as far as I can see.[/del]

How am I to get a triggering player in a timer callback?

A very good question.
 

Azlier

Old World Ghost
Reaction score
461
Really? Destroyed triggers aren't null? How am I to detect whether it has been destroyed or not, then

Edit:
How am I to get a triggering player in a timer callback?
 

Builder Bob

Live free or don't
Reaction score
249
Really? Destroyed triggers aren't null? How am I to detect whether it has been destroyed or not, then?

If I only knew. This always seem to complicate my code a lot more than I'd like...

Edit: GetTriggerExecCount() and GetTriggerEvalCount() will report 0 for destroyed triggers. It will also report 0 for newly created triggers though, so it's not going to be a safe way to determine if the trigger has been destroyed or not unless you do something clever.
 

Azlier

Old World Ghost
Reaction score
461
Ah well. A shame, that is. :(

See my last post as an 'answer' to your last question.
 

Builder Bob

Live free or don't
Reaction score
249
Destroyed triggers report false on IsTriggerEnabled() calls.

Here's a sure way to check if a trigger has been destroyed without affecting the game in any way.
JASS:
private function TrigState takes trigger trig returns nothing
	if IsTriggerEnabled(trig) then
		call BJDebugMsg(&quot;trigger is alive and enabled&quot;)
	else
		call EnableTrigger(trig)
		if IsTriggerEnabled(trig) then
			call DisableTrigger(trig)
			call BJDebugMsg(&quot;trigger is disabled&quot;)
		else
			call BJDebugMsg(&quot;trigger has been destroyed&quot;)
		endif
	endif
endfunction
 

Azlier

Old World Ghost
Reaction score
461
Perfect! Inserting into system now...
 

gameman

It's been a long, long time.
Reaction score
95
There was my way to make a double click, but it was made with gui and was a leaker despite my best efforts. I Have a hard time transitioning to jass but more and more useful stuff keeps popping up.
 

Azlier

Old World Ghost
Reaction score
461
Perhaps, and there was a major problem with this. If you clicked one unit, and double clicked another real quick, the system failed to register. This has been fixed.
 

Jesus4Lyf

Good Idea™
Reaction score
397
Try using Event instead of trigger chains. Trigger chains wasn't really for public release, but Event is. Event should prove to be more efficient and make your code easier to maintain. :)

(I just released it after realising this could become an epidemic of dodgey code and should be somewhat standardised instead.)

Feel free to internalise Event in your system by copying it in and making it private. That's up to you.
 

Romek

Super Moderator
Reaction score
963
JASS:
private function Actions takes nothing returns boolean
    
    globals
        private integer Id
        private unit Cu
    endglobals


I'm surprised that doesn't syntax. You should use globals like a normal, sane person though. If that gets fixed, then this system won't work anymore. Why do you do that anyway? Why not use locals?
 

Azlier

Old World Ghost
Reaction score
461
Because I'm too lazy to null a local. If you really want that "fixed", I'll do that while I'm installing multiple click support.
 

Romek

Super Moderator
Reaction score
963
> Because I'm too lazy to null a local.
But you're diligent enough to add a whole globals block?
You could've even put those globals in the globals block at the top, if locals are an issue.

> I'll do that while I'm installing multiple click support.
Do so. :)
 

Jesus4Lyf

Good Idea™
Reaction score
397
>while I'm installing multiple click support.
Don't bother. It's madness.

If you have a triple click event and a double click event, one of two options will occur:

Both will fire, making the triple click redundant.
OR
The double click will fire delayed, which is annoying for coding.

Unless we hear a useful case for triple click (where double click would fire too), I strongly suggest you drop it. ;)

Oh, and Romek, I'm pretty sure he did the globals for efficiency too. It's invisible to external users so its ok in my opinion, but at least he could take the globals block out of the function for the reason you stated about "what if its 'fixed'". :)
 

Azlier

Old World Ghost
Reaction score
461
>Both will fire, making the triple click redundant
It is indeed madness. But if TriggerHappy is copying my system and making it worse just for this madness, I'll just have to beat him.

>Both will fire, making the triple click redundant.
Not if I have 12 timers and triggers for each event. Madness.

>Unless we hear a useful case for triple click
Yeah, I want to hear one too.

>I'm pretty sure he did the globals for efficiency too
This is correct.
 

Romek

Super Moderator
Reaction score
963
> I'm pretty sure he did the globals for efficiency too
Yeah, I realised. Hence why I provided a solution which avoids getting rid of them altogether.

Take that global block outside of the function, and this'll be approved.
 

Azlier

Old World Ghost
Reaction score
461
Alrighty then. Doesn't support multiple clicks (God knows who needs those). Can't change the demo map right now, though. I don't have NewGen here.
 

Romek

Super Moderator
Reaction score
963
Approved.
 

Azlier

Old World Ghost
Reaction score
461
Thank ye.

Updated the demo map and shaved off a whopping 1 line of code. Thanks to Jesus4Lyf for the idea to shave off that 1 line.
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • The Helper The Helper:
    The bots will show up as users online in the forum software but they do not show up in my stats tracking. I am sure there are bots in the stats but the way alot of the bots treat the site do not show up on the stats
  • Varine Varine:
    I want to build a filtration system for my 3d printer, and that shit is so much more complicated than I thought it would be
  • Varine Varine:
    Apparently ABS emits styrene particulates which can be like .2 micrometers, which idk if the VOC detectors I have can even catch that
  • Varine Varine:
    Anyway I need to get some of those sensors and two air pressure sensors installed before an after the filters, which I need to figure out how to calculate the necessary pressure for and I have yet to find anything that tells me how to actually do that, just the cfm ratings
  • Varine Varine:
    And then I have to set up an arduino board to read those sensors, which I also don't know very much about but I have a whole bunch of crash course things for that
  • Varine Varine:
    These sensors are also a lot more than I thought they would be. Like 5 to 10 each, idk why but I assumed they would be like 2 dollars
  • Varine Varine:
    Another issue I'm learning is that a lot of the air quality sensors don't work at very high ambient temperatures. I'm planning on heating this enclosure to like 60C or so, and that's the upper limit of their functionality
  • Varine Varine:
    Although I don't know if I need to actually actively heat it or just let the plate and hotend bring the ambient temp to whatever it will, but even then I need to figure out an exfiltration for hot air. I think I kind of know what to do but it's still fucking confusing
  • The Helper The Helper:
    Maybe you could find some of that information from AC tech - like how they detect freon and such
  • Varine Varine:
    That's mostly what I've been looking at
  • Varine Varine:
    I don't think I'm dealing with quite the same pressures though, at the very least its a significantly smaller system. For the time being I'm just going to put together a quick scrubby box though and hope it works good enough to not make my house toxic
  • Varine Varine:
    I mean I don't use this enough to pose any significant danger I don't think, but I would still rather not be throwing styrene all over the air
  • The Helper The Helper:
    New dessert added to recipes Southern Pecan Praline Cake https://www.thehelper.net/threads/recipe-southern-pecan-praline-cake.193555/
  • The Helper The Helper:
    Another bot invasion 493 members online most of them bots that do not show up on stats
  • Varine Varine:
    I'm looking at a solid 378 guests, but 3 members. Of which two are me and VSNES. The third is unlisted, which makes me think its a ghost.
    +1
  • The Helper The Helper:
    Some members choose invisibility mode
    +1
  • The Helper The Helper:
    I bitch about Xenforo sometimes but it really is full featured you just have to really know what you are doing to get the most out of it.
  • The Helper The Helper:
    It is just not easy to fix styles and customize but it definitely can be done
  • The Helper The Helper:
    I do know this - xenforo dropped the ball by not keeping the vbulletin reputation comments as a feature. The loss of the Reputation comments data when we switched to Xenforo really was the death knell for the site when it came to all the users that left. I know I missed it so much and I got way less interested in the site when that feature was gone and I run the site.
  • Blackveiled Blackveiled:
    People love rep, lol
    +1
  • The Helper The Helper:
    The recipe today is Sloppy Joe Casserole - one of my faves LOL https://www.thehelper.net/threads/sloppy-joe-casserole-with-manwich.193585/
  • The Helper The Helper:
    Decided to put up a healthier type recipe to mix it up - Honey Garlic Shrimp Stir-Fry https://www.thehelper.net/threads/recipe-honey-garlic-shrimp-stir-fry.193595/
  • The Helper The Helper:
    Here is another comfort food favorite - Million Dollar Casserole - https://www.thehelper.net/threads/recipe-million-dollar-casserole.193614/

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top