| 07-26-2007, 09:21 PM | #1 |
Is there anyway to get the type of a handle easily? e.g. JASS:function bar takes handle h returns nothing local real x local real y if GetHandleType(h) == "unit" then set x = GetUnitX(x) set y = GetUnitY(y) elseif GetHandleType(h) == "location" then set x = GetLocationX(x) set y = GetLocationY(y) endif endfunction Or should I check for a properties that only a handle or each type would have. |
| 07-26-2007, 09:33 PM | #2 |
what does get handle type return? |
| 07-26-2007, 10:34 PM | #3 |
It doesn't exist. I need a function like GetHandleType() I also appear to hvae double posted. Someone should delete the other thread. |
| 07-26-2007, 11:26 PM | #4 |
There is, wrap all of the create functions to stash the type in game cache. Then wrap all the destroy functions for a sweet nectar of debug information. |
| 07-27-2007, 04:27 AM | #5 |
The only practical use for such a function would be a widget dies event. And in those events you can simply check the eventid or whether GetTriggerUnit() is null. Otherwise, whatever you plan to do is wrongly designed, explain it and we'll show you an alternative that doesn't require this function and is probably easier to code as well... |
| 07-27-2007, 07:19 AM | #6 |
Well, I want to create a coordinate system. JASS:function SetCoord takes coord c, handle h return nothing if GetHandleType(h) == "location" then set c.x = GetLocationX(l) set c.y = GetLocationY(l) call RemoveLocation(l) elseif GetHandleType(h) == "unit" then set c.x = GetUnitX(h) set c.y = GetUnitY(h) elseif //Widgets/lighting/whatever endif endfunction I know something like this is lazy and probably a bad idea if it gets too complicated, but having to set x/y manually is driving me crazy. |
| 07-27-2007, 07:25 AM | #7 |
Show us how you want to use the system. |
| 07-27-2007, 07:46 AM | #8 |
Something like this: JASS:struct xy real x real y static method Create takes handle h returns nothing local xy p = xy.allocate() // Set it to the appropriate coordinates endmethod method Distance takes xy p, xy l returns integer local real x = l.x - p.x local real y = l.y - p.y return SquareRoot(x * x + y * y) endmethod endstruct function Distance takes nothing returns nothing local xy p = xy.Create(GetTriggerUnit()) local xy l = xy.Create(GetSpellTargetLoc()) call BJDebugMsg(Distance(p. l)) endfunction |
| 07-27-2007, 01:49 PM | #9 |
haha fun stuff. JASS:struct xy real x real y static method CreateFromUnit takes unit u returns nothing local xy p = xy.allocate() //... endmethod static method CreateFromLocation takes unit u returns nothing local xy p = xy.allocate() //... endmethod method Distance takes xy p, xy l returns integer local real x = l.x - p.x local real y = l.y - p.y return SquareRoot(x * x + y * y) endmethod endstruct Although I think interfaces were meant for this. JASS:interface xy real x real y method move takes real px , real py returns nothing endinterface function DistanceBetween takes xy a, xy b returns real return SquareRoot( (a.x - b.x )*(a.x - b.x )+(a.y - b.y )*(a.y - b.y ) endfunction struct xy_unit extends xy unit u static method create takes unit u returns xyunit local xyunit r=xyunit.allocate() set r.u=u set r.x=GetUnitX(u) set r.y=GetUnitY(u) return r endmethod method move takes real px, real py returns nothing call SetUnitX(this.u, px) call SetUnitY(this.u, py) set this.x=px set this.y=py endmethod endstruct |
