| 12-17-2007, 02:20 PM | #1 |
Well, me and timers have a history. I hate them, they don't work for me. That's about it. Now, would anyone like to tell me how this: JASS:function Prey_Dies_Conditions takes nothing returns boolean return GetOwningPlayer(GetTriggerUnit()) == Player(13) endfunction function Prey_Dies_Callback takes nothing returns nothing local unit u = GetTriggerUnit() local integer i = GetUnitUserData(u) local integer id = GetUnitTypeId(u) local real x = GetLocationX(udg_NLocs[i]) local real y = GetLocationY(udg_NLocs[i]) local player p = GetOwningPlayer(u) set u = CreateUnit(p, id, x, y, GetRandomReal(0., 360.)) call SetUnitUserData(u, i) call DestroyTimer(GetExpiredTimer()) set u = null set p = null endfunction function Prey_Dies_Actions takes nothing returns nothing local timer t = CreateTimer() call TimerStart(t,GetRandomReal(420.0, 600.0), false, function Prey_Dies_Callback) endfunction //=========================================================================== function InitTrig_Prey_Dies takes nothing returns nothing local trigger t = CreateTrigger() call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_DEATH ) call TriggerAddCondition(t, Condition( function Prey_Dies_Conditions ) ) call TriggerAddAction(t, function Prey_Dies_Actions ) set t = null endfunction Is not working? DETAILS: GetUnitUserData is used because all prey have a number indexed to them. This number allows me to grab their index in the udg_NLocs array, which contains all their locations, and then make a replacement unit. |
| 12-17-2007, 02:31 PM | #2 |
You sure the conditions are right? That would be player neutral victim. Place a debug message in the Prey_Dies_Actions to be sure the trigger is executed. Also, I don't like the unnefficient use of locals in the timer callback function. You don't need a local for x,y,id,p. |
| 12-17-2007, 02:45 PM | #3 |
GetTriggerUnit won't return a valid unit when executed in a timer. All your variables are not set to what you'd expect. |
| 12-17-2007, 02:50 PM | #4 |
Goddamit. Well, I guess that's why none of my timer stuff worked. Thanks for that, that'll help a lot in the future. Handle Vars to the rescue! |
| 12-17-2007, 02:52 PM | #5 |
Oh my god, can't believe I forgot that -.- You'd have to attach the triggering unit to the timer using ABC (cohadar!!11one), DataSystem or gamecache. |
| 12-17-2007, 03:09 PM | #6 |
Fuck ABC, I don't need that massive system for something like this. I've got KaTTaNa's handle vars and that's fine by me. Thanks both of you for pointing that out. To be honest, that's been the problem this whole time. I thought GetTriggerUnit() worked in Timer callbacks. Thanks so much for correcting me! |
| 12-17-2007, 03:20 PM | #7 |
Well I honestly don't like Handle Vars due to the crappy speed, so I'd suggest you try out DataSystem (it's clean, small and no I2H bug!): http://hilton.vs.oiccam.com/pastebin...3ffd04408ae7e1 There is also another neat function for attaching structs to timers, called TimerUserData. I can't seem to find it... lemme look some more... AH got it: JASS:library TimerUserData //========================================================================================== // TimerUserDataS by DiscipleOfLife (works with timeouts ranging from 0 to 0.1) //========================================================================================== function TimerStartWithUserDataS takes timer t, real timeout, integer data, boolean periodic, code handlerFunc returns nothing call TimerStart(t, timeout+(data)/67108871., periodic, handlerFunc) endfunction function GetTimerUserDataS takes timer t, real timeout returns integer return R2I((TimerGetTimeout(t)-timeout)*67108871.+0.5) endfunction //========================================================================================== // TimerUserDataM by DiscipleOfLife (works with timeouts ranging from 0 to 1.0) //========================================================================================== function TimerStartWithUserDataM takes timer t, real timeOut, integer data, boolean periodic, code handlerFunc returns nothing call TimerStart(t, timeOut+(data)/1000000., periodic, handlerFunc) endfunction function GetTimerUserDataM takes timer t, real timeOut returns integer return R2I((TimerGetTimeout(t)-timeOut)*1000000.+0.5) endfunction endlibrary |
| 12-17-2007, 03:35 PM | #8 | |
Quote:
I am always amazed how people get terrified from the code they do not understand. What does massive mean anyways? Too much code? 400 lines... Vexorian's CSData would be a good system of choice for attahing if you like small code. But something tells me that in your particular case it would not be enough. Hint: if you find yourself using UnitUserData too often you might consider using PUI. |
| 12-17-2007, 04:10 PM | #9 | |
I just don't need ABC for what I'm doing. HandleVars may be slower, but it's what I've got and I know how to use it well. Thanks for all your input, but for something small like this, Handle Vars will be my choice. Maybe on my other project (AoS) I'll have use for something like PUI or CSData. Quote:
|
| 12-17-2007, 04:19 PM | #10 |
I don't recommend using gamecache for timers, its a really old method, has problems that arise (problems that seem completely random and hopeless), and is slow. If I were you I'd bite the bullet and invest some time checking out more recent discoveries that replace gamecache, they are way easier to use, and generally more stable. But if you want to stick with gamecache because you know gamecache well then... That is your decision! |
| 12-18-2007, 02:24 PM | #11 |
I don't recommend using gamecache for anything except for what it was originally designed: passing data between missions in campaign. |
| 12-18-2007, 11:30 PM | #12 |
Gamecache is fine for storing information you don't need every hundredth of a second. The complete boycott of gamecache is ridiculous. Every system or method has stuff it excels at and stuff it doesn't. I don't think it would make sense to use ABC for information that should be stored for 40 seconds before being used again. Use gamecache, since it is native and efficiency isn't key. |
| 12-19-2007, 12:18 AM | #13 | |
Quote:
Thats the exact same as my HSAS except mine is more sophisticated |
| 12-19-2007, 12:49 AM | #14 |
I think that in vJass we'll soon have a [] operator for global arrays so the result would be: JASS:globals private integer array data [65000] endglobals function get takes handle h returns integer return data[H2I(h)-0x100000 ] endfunction With inliner optimizer added later it could even get converted directly and take only one function call. but 65000 handles still sound like too few. So, I think we could just forget about attaching things to timers, not like that was necessary... |
| 12-19-2007, 02:45 AM | #15 |
It is still "needed" in the case that each instance of a timer can have an arbitrary expiration length and you don't want to use something like your MagicTimers for performance concerns. I think that has only happened to me once so far. So it's a rare situation. |
