| 08-04-2007, 01:10 AM | #1 |
What uses for setting the custom value or SetUnitUserData do you have? Do any particular posted systems here use them so it might be a bad idea to alter them otherwise? Might it be a bad idea to set a custom value to every unit in the map? Also about handle variables. I understand what they are but what kind of uses does a handle variable have? |
| 08-04-2007, 02:00 AM | #2 |
Well... if you don't want to loop through the array indicies of a struct you can store the value in the custom user data or a handle variable on a timer then retrieve it. Handle variables? I don't know. Be creative, if you want to, you can use them for pretty much anything that involves storing data in gamecache if you don't care about running into possible errors or lag. |
| 08-04-2007, 07:37 PM | #3 |
For me the greatest use of handles is with timers. I just started using both, and you cant forward local variables into the timer callback functions, so you set handles on a timer, and u can still access them in the timer callback function. ![]() |
| 08-04-2007, 07:45 PM | #4 |
Structs for the UserData. But if youre gona go that route definately use CSData as UserData gets instantly cleared when the unit dies and you'll lose your pointer/reference for the struct making it more complicated to destroy it |
| 08-04-2007, 11:09 PM | #5 | |
Quote:
Care for an example? It would help me loads cause I need a solution to that. |
| 08-04-2007, 11:21 PM | #6 |
http://wc3campaigns.net/pastebint.ph...3ffd04408ae7e1 Like UnitUserData(), but for handles instead of units. Anyway, structs can be cast to integers. Thusly you can attatch structs to units with UnitUserData(). Handle vars...? as in local handle variables? if so, theyre evil and out-dated. (they are evil due to string leaks and I2H() usage. This can cause bugs that are nigh-impossible to fix) Structs and things like DataSystem make them no longer needed. |
| 08-05-2007, 10:12 PM | #7 | |
Quote:
JASS:function move_callback takes nothing returns nothing local timer t = GetExpiredTimer() local unit theunit = GetHandleUnit(t, "unot") local location spot = GetUnitLoc(theunit) local real newx = (GetLocationX(spot) + 4) local integer frame = GetHandleInt(t, "frame") call SetUnitX(theunit, newx) if (frame == 10) then call FlushHandleLocals(t) call DestroyTimer(t) return endif call SetHandleInt(t, "frame", (frame+1) endfunction function moveunit takes unit theunit returns nothing local timer t = CreateTimer() call SetHandleHandle(t, "unot", theunit) call SetHandleInt(t, "frame", 1) call TimerStart(t, 0.05, true, function move_callback) endfunction this makes the unit move to the right 10 times, every 0.05 of a second. its just a simple example so there are some leaks but you get the idea. All the data you need is stored in the timer t so it can be accessed from the callback. ![]() |
