Handle Vars

Frizz.Meister

New Member
Reaction score
0
A simple question really but i cant seem to work out how to actually use handle vars. I know what they do and how they do it but they never work for me.

Would it be possible for someone to post a trigger moving a unit from initial function to a timer function.

JASS:
unction Timer_Func takes nothing returns nothing
    call KillUnit( tu )
endfunction
        
function Init takes nothing returns nothing
    local timer t=CreateTimer()
    local unit tu=GetSpellTargetUnit()
    call TimerStart(t, 0.05, true, function Timer_Func)
    call TriggerSleepAction(1)
    call DestroyTimer(t)
    set t=null
endfunction


I know its not the best example but i want to move tu to the function Timer_Func

any help?
 

Romek

Super Moderator
Reaction score
964
I recommend Timer Utils.
I agree that Tom Jones' method is a bit difficult for a complete beginner. :p

Though, I don't use any attachment with high frequency timers.
 

Frizz.Meister

New Member
Reaction score
0
Actually Tom Jones got it perfect thanks a lot man you saved me a lot of time. However just out of curiosity how would a timer attach system help any more than a standard timer if i wasnt going to recycle it?
 

quraji

zap
Reaction score
144
It's not overkill, but some explanation would be handy..

With Tom's snippet (which assumes you use vJass):
JASS:

// every handle (unit, effect, timer, etc) gets a unique id when it is created,
// this will return that id
function H2I takes handle h returns integer
    return h
    return 0
endfunction

// an array for storing the struct ids
globals
    integer array S
endglobals

// structs are an easy way to hold lots of data for attaching, since all you
// need to access the data is the struct id
struct data
    unit u
    // you could have more things here (more units, groups, whatever)
endstruct

// read below first
function Callback ...
    local data s = S[H2I(GetExpiredTimer())-0x100000] // retrieve the struct
                                                                         // from the array using
                                                                         // the timer's id

    call KillUnit(s.u)
endfunction

function ...
    local data s = data.create()   // create the struct
    local timer t = CreateTimer()

    set s.u = ...
    set S[H2I(t)-0x100000] = s // save the struct id into the array
                                          // the index of the array is the id of the timer
                                          // minus the hex value 0x100000 because
                                          // that is the hex number at which handle ids
                                          // start (so that they'll fit into the array)
                                          // if you don't understand this part say so

    call TimerStart(t,0.01,false,function Callback) // start the timer
    set t = null
endfunction
 

Joker(Div)

Always Here..
Reaction score
86
Actually Tom Jones got it perfect thanks a lot man you saved me a lot of time. However just out of curiosity how would a timer attach system help any more than a standard timer if i wasnt going to recycle it?
It recycles for you. You just need to change the function names.

CreateTimer() -> NewTimer()
DestroyTimer() -> ReleaseTimer()

The the Romek linked uses a timer stack and resues them as needed.

Also, the attachment systems save you quite a bit of time.
 

Frizz.Meister

New Member
Reaction score
0
Although what you said makes sense to me. The trigger doesnt work. I looked around the web and from what i can gather i need to set a game cache, is this correct or is my mistake something else?

anyway here is my entire trigger
JASS:
globals
    data array KBD
endglobals

struct data
    unit u
endstruct

function H2I takes handle h returns integer
    return h
    return 0
endfunction

function Kill_Func takes nothing returns nothing
    local data s = KBD[H2I(GetExpiredTimer())-0x100000]
     call KillUnit(s.u)
endfunction
        
function Trig_trig_dummy_Actions takes nothing returns nothing
    local data s = data.create()
    local timer t = CreateTimer()
    set s.u =  (GroupPickRandomUnit(udg_TempGroup))
    set KBD[H2I(t)-0x100000] = s
    call TimerStart(t,0.05,true,function Kill_Func)
    call TriggerSleepAction(1)
    set t = null
endfunction

//===========================================================================
function InitTrig_trig_dummy takes nothing returns nothing
    set gg_trg_trig_dummy = CreateTrigger(  )
    call TriggerRegisterTimerEventSingle( gg_trg_trig_dummy, 400.00 )
    call TriggerAddAction( gg_trg_trig_dummy, function Trig_trig_dummy_Actions )
endfunction


If it helps the event is after 400 seconds have passed.

Edit: Also it ment to be a repeating action with the timer so more like
JASS:
    call TimerStart(t, 0.05, true, function My_Func)


Sorry for not making this clear earlier
 

Viikuna

No Marlo no game.
Reaction score
265
A bit overkill for a beginninger, No? Why not link to some timer attach system?

I hate when people say that.

Anyways, if H2I( timer ) - 0x100000 is greater than 8191 ( Jass array size ), you need to use vJass´s bigger arrays ( which are slower ).

Recycling timers is also a good idea.

edit. I actually wrote a tutorial about timer attaching. link
 

Frizz.Meister

New Member
Reaction score
0
the tutorial helped but it doesnt explain how to attach units only locations and integers. Im looking at the attaching data to timers section, just above the timer system section. Or can units simply be attached in the same way?

eg.
JASS:
local unit u=GetTriggerUnit()
      local integer handleID=H2I(u)


or would this not work?
 

Viikuna

No Marlo no game.
Reaction score
265
You should only attach integers ( structs ) to handles.

JASS:
struct Data
   unit u // you can have all data you need inside your struct
   location loc
   player p

endstruct


You can use H2I to unit too, but units also have UnitUserData so you should use it to index them.

edit. Yes, unit is a handle. You should check common.j and see which things extend handle.
 

Akolyt0r

New Member
Reaction score
33
TimerUtils (Red) is the best attachment system for timers ever ...

H2I(t)-OFFSET (without recycling timers) will break if you spawn many units and/or have leaks in your map ...
If you use a Damage Detection system there is no way around leaks anyway ..so you would hit that limit of 8190 handles pretty fast...

TimerUtils (red) use H2I(t)-OFFSET aswell ....but the timers for TU (red) are all created at map init ..so its ensured that they will be in the 8190 range...
 

Viikuna

No Marlo no game.
Reaction score
265
IMO the best way is to use struct arrays for periodic stuff

( fast & has no limits, but is practical only for periodic timers. )

and TimerUtils(Red) ( fast or some other TimerStack script for the rest.

( fast but has only limited amout of timers. )
 

Akolyt0r

New Member
Reaction score
33
IMO the best way is to use struct arrays for periodic stuff

True, but only for stuff which is used a lot (= its pretty likely you have more than one instance of "it).
Means ...its suitable for systems and maybe even spells which are used a lot (= spells of normal units) but not for spells which arent used a lot ( hero spells ?!)
 

Viikuna

No Marlo no game.
Reaction score
265
I dont really see why it would be non suitable for spells that are not used a lot.

Well, there is nothing wrong with using TimerUtils, just make sure that you dont run out of timers.
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?
  • The Helper The Helper:
    Happy Thursday!
    +1
  • Varine Varine:
    Crazy how much 3d printing has come in the last few years. Sad that it's not as easily modifiable though
  • Varine Varine:
    I bought an Ender 3 during the pandemic and tinkered with it all the time. Just bought a Sovol, not as easy. I'm trying to make it use a different nozzle because I have a fuck ton of Volcanos, and they use what is basically a modified volcano that is just a smidge longer, and almost every part on this thing needs to be redone to make it work
  • Varine Varine:
    Luckily I have a 3d printer for that, I guess. But it's ridiculous. The regular volcanos are 21mm, these Sovol versions are about 23.5mm
  • Varine Varine:
    So, 2.5mm longer. But the thing that measures the bed is about 1.5mm above the nozzle, so if I swap it with a volcano then I'm 1mm behind it. So cool, new bracket to swap that, but THEN the fan shroud to direct air at the part is ALSO going to be .5mm to low, and so I need to redo that, but by doing that it is a little bit off where it should be blowing and it's throwing it at the heating block instead of the part, and fuck man
  • Varine Varine:
    I didn't realize they designed this entire thing to NOT be modded. I would have just got a fucking Bambu if I knew that, the whole point was I could fuck with this. And no one else makes shit for Sovol so I have to go through them, and they have... interesting pricing models. So I have a new extruder altogether that I'm taking apart and going to just design a whole new one to use my nozzles. Dumb design.
  • Varine Varine:
    Can't just buy a new heatblock, you need to get a whole hotend - so block, heater cartridge, thermistor, heatbreak, and nozzle. And they put this fucking paste in there so I can't take the thermistor or cartridge out with any ease, that's 30 dollars. Or you can get the whole extrudor with the direct driver AND that heatblock for like 50, but you still can't get any of it to come apart
  • Varine Varine:
    Partsbuilt has individual parts I found but they're expensive. I think I can get bits swapped around and make this work with generic shit though
  • Ghan Ghan:
    Heard Houston got hit pretty bad by storms last night. Hope all is well with TH.
  • The Helper The Helper:
    Power back on finally - all is good here no damage
    +2
  • V-SNES V-SNES:
    Happy Friday!
    +1
  • The Helper The Helper:
    New recipe is another summer dessert Berry and Peach Cheesecake - https://www.thehelper.net/threads/recipe-berry-and-peach-cheesecake.194169/

      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