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

Refreshing Selection without releasing trigger?

Status
Not open for further replies.
Level 15
Joined
Nov 30, 2007
Messages
1,202
Is it possible to reselect a unit periodically every 1 second until a "real" deselection event occurs. In other words I'm trying to disable selection/deseelection detection when a refresh occurs and when a real deselection is detected i want to disable the refresh.

Something like this:

Player 1 selects Kassan and refresh should now be enabled.
  • Selected
    • Events
      • Player - Player 1 (Red) Selects a unit
    • Conditions
      • (Triggering unit) Equal to Jailor Kassan 0001 <gen>
    • Actions
      • Game - Display to (All players) the text: Selected
      • Trigger - Turn on Refresh <gen>
Refresh will periodically reselect Kassan but should not trigger selection/deselection events.
  • Refresh
    • Events
      • Time - Every 1.00 seconds of game time
    • Conditions
    • Actions
      • Set DESELECT_ON = False
      • Trigger - Turn off Deselected <gen>
      • Trigger - Turn off Selected <gen>
      • Game - Display to (All players) the text: Refresh
      • Selection - Clear selection for Player 1 (Red)
      • Selection - Select Jailor Kassan 0001 <gen>
      • Trigger - Turn on Selected <gen>
      • Trigger - Turn on Deselected <gen>
      • Set DESELECT_ON = True
Finally when a deselection occurs Refresh should be disabled.

  • Deselected
    • Events
      • Player - Player 1 (Red) Deselects a unit
    • Conditions
      • DESELECT_ON Equal to True
    • Actions
      • Game - Display to (All players) the text: Deselected
      • Trigger - Turn off Refresh <gen>
Currently this setup causes selection, deselection trigger to run on refresh. I even tried adding a boolean as filter and it still runs.

The output i want is something like: SELECTED REFRESH REFRESH REFRESH DESELECTED
What I get is SELECTED REFRESH DESELECTED SELECTED REFRESH DESELECTED SELCTED ... DESELECTED.

I suppose one solution is to refresh regardless of select/deselect events.
 
Last edited:
Level 15
Joined
Nov 30, 2007
Messages
1,202
The selection events are really laggy/delayed. I found that for applications like this it's much more reliable to just check IsUnitSelected on a low-timeout timer.

Oh right, I remeber you saying something like that before. ^^

This actually works:

JASS:
scope OpenCloseText initializer Init 
   
    globals 
        boolean prevSelected = false
        timer refreshTimer 
    endglobals 
   
    function OnRefreshTimer takes nothing returns nothing 
        call BJDebugMsg("Refreshing")
        if GetLocalPlayer() == Player(0) then
            call ClearSelection()
            call SelectUnit(gg_unit_ncop_0027, true)
        endif
    endfunction 
   
    function CheckForSelection takes nothing returns nothing 
        if IsUnitSelected(gg_unit_ncop_0027, Player(0)) then 
            if not(prevSelected) then 
                call BJDebugMsg("SELECTED")
                call TimerStart(refreshTimer, 1.00, true, function OnRefreshTimer)
            endif
            set prevSelected = true
        else 
            if prevSelected then 
                call BJDebugMsg("deselected")
                call PauseTimer(refreshTimer)
            endif
            set prevSelected = false
        endif
    endfunction 
   
   
    private function Init takes nothing returns nothing 
        local timer t = CreateTimer()
        call TimerStart(t, 0.03, true, function CheckForSelection)
        set refreshTimer = CreateTimer()
    endfunction
endscope
 
Last edited:
Level 15
Joined
Nov 30, 2007
Messages
1,202
Why is the clearing selection and re-selecting the unit each second wanted?

I am revisiting the SpellMenu and basically when you update an ability tooltip you need to reselect the unit for the changes to be seen. Never fully got the cooldown to update properly, so this iteration my idea is to simply disble the button and have a cooldown label to display time remaining.
 
On first look it seems less complex for me to check if the unit who gets tooltip updated is selected, and then re-select it, but I don't know your system very well. I imagined something like
Code:
function UpdateToolTip( ... )
{
    ...

    if ( GetLocalPlayer() has selected <u> ) then
        SelectUnit(GetLocalPlayer(), <u>)
    endif
    ...
}
.. it could be outsourced into a new function if gets longer.. but maybe something alike.
 
Status
Not open for further replies.
Top