• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

Timers

Status
Not open for further replies.
Level 3
Joined
Nov 27, 2008
Messages
29
Question 1: Isn't there any search function here? sorry I'm new here

Question 2: How would you attach units to timers? Can I get the format, I'm just self study in jass and still a newbie:grin:.. I wanted to make my spells MUI so I shouldn't use globals.. I mean, you create a timer, store a unit/anything to it, run the timer and you're stored unit is there.. I just can't get it to work :angry:

Tnx guyz
 
Level 9
Joined
Oct 28, 2007
Messages
435
You can do that... Um. You will need to store the unit data in the game cache... OR well thats how I would do it and it would still be MUI. I use CS_CACHE which has several such functions.

You will need. Dam. I can't remember how to store data in the Game Cache. But you will do it like this..

You will need to create a game chache and set the variable gamecache to the game cache you created

then your functions:

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

function AttachObject takes handle h, string s, handle h2 returns nothing
if h2==null then
call FlushStoredInteger(gamechache,I2S(H2I(h)),s)
else
call StoreInteger(gamechache,I2S(H2I(h)),s,H2I(h2))
endif
endfunction

function GetAttachedUnit takes handle h, string s returns unit
return GetStoredInteger(gamechache,I2S(H2I(h)),s)
return null
endfunction

This allows you to attach a unit on a time by calling AttachObject the handle is the thing you attach your variable too. This "thing" can be any unit, timer, destructable, trigger .... Secondly you have a string. This is your "save name" in a way and is used later on. Lastly you have the unit you are attaching.
Now how to use in your example:

JASS:
function Timer take nothing returns nothing
local timer t=GetExpiredTimer()
local unit u=GetAttachedUnit(t,"u") // Gets the attached unit saved under "u"
call AttachObject(t,"u",null) // This deletes the attached unit
endfunction

function SpellCast takes nothing returns nothing
local unit u=GetSpellAbilityUnit()
local timer t=CreateTimer()
call StartTimer(t,2,false,function Timer)
call AttachObject(t,"u",u) // Stores a unit under u on the target
endfunction

Umm. I hope you understand since my explanation is quite crappy.
 
Status
Not open for further replies.
Top