function wraper or hook?

Tom_Kazansky

--- wraith it ! ---
Reaction score
157
I think of using a timer to track whether a unit is moving (run, walk) or not so I attach 2 real values (x, y coordinate) to it. These are updated frequently.

now I guess I have to update these whenever the unit is moved by [ljass]SetUnitX[/ljass], [ljass]SetUnitY[/ljass], [ljass]SetUnitPosition[/ljass] (well, I only use these)

function wraper:
JASS:

function SetUnitXEx takes unit u, real x returns nothing
    call SetUnitX(u,x)
    //update x coordinate for u
endfunction
function SetUnitYEx takes unit u, real y returns nothing
    call SetUnitY(u,y)
    //update y coordinate for u
endfunction
function SetUnitPositionEx takes unit u, real x, real y returns nothing
    call SetUnitPosition(u,x,y)
    //update x coordinate for u
    //update y coordinate for u
endfunction


hook:
JASS:

hook SetUnitX hook_SetUnitX
hook SetUnitY hook_SetUnitY
hook SetUnitPosition hook_SetUnitPosition

function hook_SetUnitX takes unit u, real x returns nothing
    //update x coordinate for u
endfunction
function hook_SetUnitY takes unit u, real y returns nothing
    //update y coordinate for u
endfunction
function hook_SetUnitPosition takes unit u, real x, real y returns nothing
    call SetUnitPosition(u,x,y)
    //update x coordinate for u
    //update y coordinate for u
endfunction


err... so, which way is more efficient? :confused: or they're the same?
 

Solmyr

Ultra Cool Member
Reaction score
30
Use GetMovingUnit already which solves these problems?

You do realize that the [ljass]GetMovingUnit()[/ljass] function is only to be used within the callbacks of the [ljass]MOVE[/ljass] and [ljass]STOP[/ljass] events that the library provides, right? There are the [ljass]readonly x[/ljass] and [ljass]y[/ljass] fields of the [ljass]UnitMoving[/ljass] struct (the struct's id is the same as the unit's id), which provide access to the unit's last checked x and y coordinates, but I don't know if that's what Tom_Kazansky wants.

Anyway, use function wrappers. Hooks are called via trigger evaluations and are considerably slower (and may actually cause a problem if you're doing the stuff too frequently).
 

Tom_Kazansky

--- wraith it ! ---
Reaction score
157
I actually want to get the angle at which the unit is moving, so IsUnitMoving won't do, but I guess it have something I can learn from :D

Anyway, use function wrappers. Hooks are called via trigger evaluations and are considerably slower (and may actually cause a problem if you're doing the stuff too frequently).

thanks, +rep
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      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