• 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.

Convert timer handle id to timer.

Status
Not open for further replies.
Level 23
Joined
Apr 16, 2012
Messages
4,041
Simple, you cant :D

HandleId is integer, after 1.23B or 1.24 you cant typecast, so you cant convert integer to anything other than real.

Why do you want to do this anyways? Show some usable example, there most likely is a alternative way to do this, but it really depends on context
 
I'm not sure I quite understand.

HandleId is an integer. Timer is new complex type. So you can't.

Yan can save a timer (handle) into hashtable with using any HandleId as key.
You can load a timer (handle) from hashtable with using the same HandleId as key.

native SaveTimerHandle takes hashtable table, integer parentKey, integer childKey, timer whichTimer returns boolean

native LoadTimerHandle takes hashtable table, integer parentKey, integer childKey returns timer

Maybe this helps, too:
native GetExpiredTimer takes nothing returns timer
^It obviously returns the current timer that expired.
 
Level 28
Joined
Sep 26, 2009
Messages
2,515
I think what OP wants is something akin to this:
If you call getHandleID(timer), you get handle id of said timer. He wants a reverse of this process. So something like getTimer(handleID) which would return timer.
I don't think it exists imo, I'm not sure if there is any specific way for assigning IDs to different types of objects.
For example a handle ID 158541676 could be timer, but who knows? It may be unit or a special effect.
 
Level 24
Joined
Aug 1, 2013
Messages
4,658
Simple, you cant :D

I don't think it exists imo, I'm not sure if there is any specific way for assigning IDs to different types of objects.

I'm not sure I quite understand.

HandleId is an integer. Timer is new complex type. So you can't.

Yan can save a timer (handle) into hashtable with using any HandleId as key.
You can load a timer (handle) from hashtable with using the same HandleId as key.

native SaveTimerHandle takes hashtable table, integer parentKey, integer childKey, timer whichTimer returns boolean

native LoadTimerHandle takes hashtable table, integer parentKey, integer childKey returns timer.

Sorry IcemanBo but that is a contradiction in terms.
You say "So you can't."
Then you say "This is how you must do it."

JASS:
function GetTimerById takes integer id returns timer
    return LoadTimerHandle(udg_Timer_Hashtable, id, 0)
endfunction

function SaveTimer takes timer t returns nothing
    call SaveTimerHandle(udg_Timer_Hashtable, GetHandleId(t), 0, t)
endfunction

Ofcourse you have to call SaveTimer() after each and every CreateTimer() that you might want to get back but who the hell cares?

Next to that, now that I see this, I see that I can just use SaveTimerHandle and LoadTimerHandle because the handle id of the timer was saved in a hashtable... It looks like I have to read all the datatypes you could save in a hashtable again.

Anyway thanks for the help +rep
 
You do not convert any HandleId into a timer. You just use it as key, when you save/load.

JASS:
function GetTimerById takes integer id returns timer
    return LoadTimerHandle(udg_Timer_Hashtable, id, 0)
endfunction

function SaveTimer takes timer t returns nothing
    call SaveTimerHandle(udg_Timer_Hashtable, GetHandleId(t), 0, t)
endfunction
You save the timer handle with using the HandleId of itself.

Then you want to load the timer basing on a given HandleId. Where should you get this HandleId from?
That implies you already have the timer, so:

call GetTimerById(GetHandleId(myTimer)) will again return "myTimer".
 
Level 23
Joined
Apr 16, 2012
Messages
4,041
LoadTimerHandle != GetHandleId.

Pick whichever you mean, you said handle of timer, this can mean various things, thats why I said to be more specific.

Also while you are right, but it is not entirely true. You dont save the handle id of timer into hashtable. You store the timer under X index of handle id of the timer, and Y of 0.

Imagine it as 2D map with X and Y coordinates, which can only be integers. And you can put anything in there(basic types will stack btw). This is fundamentally different, because as mentioned, handle id is a mere integer, while the object, or you could say, the handle is the real entity that the game works with
 
Level 24
Joined
Aug 1, 2013
Messages
4,658
You do not convert any HandleId into a timer. You just use it as key, when you save/load.
Difference = null

Then you want to load the timer basing on a given HandleId. Where should you get this HandleId from?
That implies you already have the timer, so:

call GetTimerById(GetHandleId(myTimer)) will again return "myTimer".

GetHandleId(TimerA) = 1049104 (example)
GetTimerById(1049104) = TimerA

As I mentioned, you have to register the data first.
But if you only have an integer (the handle id) you can convert it into the timer.
I have to stop a timer somewhere while the timer is still running.
Thats why I couldnt use GetExpiredTimer().

LoadTimerHandle != GetHandleId.

Pick whichever you mean, you said handle of timer, this can mean various things, thats why I said to be more specific.
Title: "Convert timer handle id to timer"
handle of timer = timer (object)
handle id of timer = timer.id (unique integer)
handle of timer means only one thing.

Also while you are right, but it is not entirely true. You dont save the handle id of timer into hashtable. You store the timer under X index of handle id of the timer, and Y of 0.
You turn around the question. The question was how do you get the timer if you have its handle id.
If you save the timer in an array/hashtable under the index of handle id (and 0) you can get the timer if you have its handle id.[/QUOTE]
 
Level 22
Joined
Sep 24, 2005
Messages
4,821
What they were saying is that you can also use a unit's any handle Id to store the timer using a hashtable since the keys it takes as arguments are just plain integers.

so doing something like this is ok too:
JASS:
function GetTimerById takes integer id returns timer
    return LoadTimerHandle(udg_Timer_Hashtable, id, 0)
endfunction

function SaveTimer takes timer t returns nothing
    call SaveTimerHandle(udg_Timer_Hashtable, GetHandleId(CreateGroup()), 0, t)
endfunction
 
Level 23
Joined
Apr 16, 2012
Messages
4,041
there is only one way to achieve this, and that is downgrading your game below 1.23B and using typecasting exploit. There is absolutly no other way to convert integer to anything else than real or string.

Also Iceman as well as chobibo wrote you a way to do something like this. You will have to store the integer somewhere, and save the timer into hashtable, then when you want to pause it you fetch(oh php what are you doing to my mind) the timer from hashtable with parentkey being the handle id of the timer, and child key anything you saved it at.
 
Level 12
Joined
Feb 22, 2010
Messages
1,115
Well if you want your own GetTimerById function you need to save the timer somewhere.The functions made by chobibo has right approach but either I am really stupid now or the method that chobibo shows is really stupid.He is attaching timer to an unknown unit group handle ID which we will never know(almost) and then to retrieve timer back he wants this unknown handle ID.

Edit: I assume it must be GetHandleId(t) and everything is ok.
 
Level 24
Joined
Aug 1, 2013
Messages
4,658
JASS:
function GetTimerById takes integer id returns timer
    return LoadTimerHandle(udg_Timer_Hashtable, id, 0)
endfunction

function SaveTimer takes timer t returns nothing
    call SaveTimerHandle(udg_Timer_Hashtable, GetHandleId(t), 0, t)
endfunction

That is the function to get a timer if you have its handle id.
However chobibo also mentioned that you could use any integer to get it.
Like instead of using the handle id of the timer, you could use the handle id of the unit group instead... if you have saved the timer under the key of the unit group ofcourse.

GetHandleId(t) is standard.
GetTimerById(id) is the one I needed.
 
Status
Not open for further replies.
Top