wc3campaigns
WC3C Homepage - www.wc3c.netUser Control Panel (Requires Log-In)Engage in discussions with other users and join contests in the WC3C forums!Read one of our many tutorials, ranging in difficulty from beginner to advanced!Show off your artistic talents in the WC3C Gallery!Download quality models, textures, spells (vJASS/JASS), systems, and scripts!Download maps that have passed through our rigorous approval process!

Go Back   Wc3C.net > Warcraft III Modding > Developer's Corner > Triggers & Scripts
User Name
Password
Register Rules Get Hosted! Chat Pastebin FAQ and Rules Members List Calendar



Reply
 
Thread Tools Search this Thread
Old 05-02-2009, 10:21 PM   #1
Cheezeman
User
 
Cheezeman's Avatar
 
Join Date: Apr 2009
Posts: 179

Cheezeman has little to show at this moment (1)

Question Getting an unit's 'id-number'

Hey dudes!

Is there a way to get a unit's id? I mean, like a real id-number in integers, but for a widget? Or real, I don't really care.
Something like "GetUnitIdNumber( Unit )", which is an integer.
(I know I just made that function up, I just wrote it so you'd understand what I'd like)

I asked this in hiveworkshop.com before, and someone told me that I should use something called Handle2Integer (H2I) but I have no idea how to use it, or what it does.

Now, I have a request too.
Could you please not go too deep into advanced functions and such?
As you might have already seen, I'm very new to this vJass and all. I've just begun using scope for a spell I'm developing, so I don't know squat about anything beyond those bonds (labraries, structs etc.).
Telling me things beyond scopes and such would just be a huge waste of time since I'll probobly end up scratching my head and looking like this dude (although I'm quite sure my face wouldn't be green).

All help apreciated!
Cheezeman
__________________
I have no signature yet
Cheezeman is offline   Reply With Quote
Sponsored Links - Login to hide this ad!
Old 05-02-2009, 10:55 PM   #2
MaD[Lion]
MaD Da ViNci
 
MaD[Lion]'s Avatar


Respected User
 
Join Date: Apr 2003
Posts: 1,699

Submissions (10)

MaD[Lion] is a jewel in the rough (225)MaD[Lion] is a jewel in the rough (225)MaD[Lion] is a jewel in the rough (225)MaD[Lion] is a jewel in the rough (225)

Default

u can get its handle id by abusing the return bug. but it require u to make a function for it first:
Collapse JASS:
function H2I takes handle h returns integer
    return h
    return 0
endfunction

...


local integer UnitId = H2I(GetTriggerUnit())
__________________
Current Projects:
MaDOS (outdated)System for object movements & effects - NEW VERSION IS UNDER W.I.P
Cinematic SystemSystem for making better cinematics and with fancy effects
Timing SystemTiming system that simulates the usage of PolledWait just with 0.01 accuracy
MaD[Lion] is offline   Reply With Quote
Old 05-02-2009, 11:26 PM   #3
Viikuna-
User
 
Viikuna-'s Avatar
 
Join Date: Feb 2009
Posts: 203

Viikuna- will become famous soon enough (44)Viikuna- will become famous soon enough (44)

Default

H2I gives you an unique value, but note that it is too big to be used as an array index. ( You can always decerease it, or hash it or something )

You can also use GetUnitUserData, but it requires you to set different numbers to all units, by using SetUnitUserData.
__________________
No Marlo, no game.
Viikuna- is offline   Reply With Quote
Old 05-02-2009, 11:43 PM   #4
grim001
requires vJass
 
grim001's Avatar


Code Moderator
 
Join Date: Nov 2006
Posts: 1,540

Submissions (10)

grim001 is just really nice (277)grim001 is just really nice (277)

Send a message via AIM to grim001
Default

If you plan to attach data to a unit with the ID number you get from H2I(u) it won't work. The value you get from H2I is too big to fit in JASS's little 8191 sized arrays.

You can deal with this in a number of ways. First you could try using this code:
Collapse JASS:
function H2I takes handle h returns integer
    return h
    return 0
endfunction

function GetUnitIndex takes unit u returns integer
    return H2I(u) - 0x100000
endfunction
0x100000 is hexadecimal for the first handle's ID, subtracting it will bring the IDs down to a range where they fit inside JASS arrays.

However, it is a common issue that you will still get more than 8191 handles in a map (whether because it's a big map or because you are leaking). To deal with this, you need to use bigger arrays. vJASS has a syntax for extending the size of arrays, but it's slower:
Collapse JASS:
globals
    integer array MyUnitData[24573] //3x the size of normal array
endglobals

function SetMyUnitData takes unit u, integer i returns nothing
    set MyUnitData[GetUnitIndex(u)] = i
endfunction

function GetMyUnitData takes unit u returns nothing
    return MyUnitData[GetUnitIndex(u)]
endfunction

This is starting to sound like a huge pain in the ass, right? It can still break if you keep leaking or creating new handles until you get more than 24573 (or whatever value you've chosen) handles, and it generates tons of extra code.

There are a few alternatives to this. First, you can use gamecache or Table to attach data to the H2I ID of the unit. It's easy because gamecache has no size limits or other nonsense to deal with, but it is slower.

However, the fastest way to deal with it is to use SetUnitUserData/GetUnitUserData to store a unique integer on every unit in your map. Then you can just use the "GetUnitId" function to grab the ID. This is called unit indexing. You can look at UnitIndexingUtils or AutoIndex for that.
grim001 is offline   Reply With Quote
Old 05-03-2009, 02:45 AM   #5
Silvenon
User
 
Silvenon's Avatar
 
Join Date: May 2007
Posts: 492

Submissions (1)

Silvenon will become famous soon enough (63)Silvenon will become famous soon enough (63)Silvenon will become famous soon enough (63)

Send a message via MSN to Silvenon
Default

Lol, grim, nice :D

Cohadar made a system like that too, PUI.
__________________
Cascading Style Shit
Silvenon is offline   Reply With Quote
Old 05-03-2009, 08:45 AM   #6
Cheezeman
User
 
Cheezeman's Avatar
 
Join Date: Apr 2009
Posts: 179

Cheezeman has little to show at this moment (1)

Default

Quote:
Originally Posted by Viikuna-
H2I gives you an unique value, but note that it is too big to be used as an array index. ( You can always decerease it, or hash it or something )

You can also use GetUnitUserData, but it requires you to set different numbers to all units, by using SetUnitUserData.

I'm actualy using GetUnitUserData() in my spell right now. However, I want to get rid of it.
You see, this work is not for a map, but for a spell. I'm planning on releasing this in public and it should be 100% multi-instancable and self-sufficient.
Problem is that it uses TriggerSleepAction( Duration(level) ) between two loops to state that it's waiting, so if a guy wants this in his map - but use SetUnitUserData() for other purposes - this is an impossibility.

Now you may ask ok, why not use integer array and compare the results? (ok maybe you're not but still)
This is an impossibilty aswell, since it's got a long wait between my two loops, and a map-maker can change the values in-between.

I won't go any deeper since I will just have to explain more and more of my code, I think it will be easier if I just post it here later.

Quote:
Originally Posted by grim001
If you plan to attach data to a unit with the ID number you get from H2I(u) it won't work. The value you get from H2I is too big to fit in JASS's little 8191 sized arrays.
No, I was thinking of making set Integer_Array[UnitIdNumber] = Integer_Array[UnitIdNumber] + 1. Hm... perhaps that's what you asked for :P
Arrays have a size limit in Jass?! Thanks for the info

Quote:
Originally Posted by grim001
You can deal with this in a number of ways. First you could try using this code:
Collapse JASS:
function H2I takes handle h returns integer
    return h
    return 0
endfunction

function GetUnitIndex takes unit u returns integer
    return H2I(u) - 0x100000
endfunction
0x100000 is hexadecimal for the first handle's ID, subtracting it will bring the IDs down to a range where they fit inside JASS arrays.

However, it is a common issue that you will still get more than 8191 handles in a map (whether because it's a big map or because you are leaking). To deal with this, you need to use bigger arrays. vJASS has a syntax for extending the size of arrays, but it's slower:
Collapse JASS:
globals
    integer array MyUnitData[24573] //3x the size of normal array
endglobals

function SetMyUnitData takes unit u, integer i returns nothing
    set MyUnitData[GetUnitIndex(u)] = i
endfunction

function GetMyUnitData takes unit u returns nothing
    return MyUnitData[GetUnitIndex(u)]
endfunction

This is starting to sound like a huge pain in the ass, right? It can still break if you keep leaking or creating new handles until you get more than 24573 (or whatever value you've chosen) handles, and it generates tons of extra code.
Well, that's really up to the user. If he wants this spell's area of effect to be 10,000 and fill up a lot of units in it, that's his decision, not mine.
But I think this might solve my problem, I'll try implenting this in my spell and see if I get somewhere.
Since this is a quite small aoe spell I'm making (I don't think anyone will use it with more than 1000 aoe) and it filters a lot of units, I think can make the id-number even smaller, but I'm not sure how...
Just add another 0 at the end of the hexadecimal?

Quote:
Originally Posted by grim001
There are a few alternatives to this. First, you can use gamecache or Table to attach data to the H2I ID of the unit. It's easy because gamecache has no size limits or other nonsense to deal with, but it is slower.

However, the fastest way to deal with it is to use SetUnitUserData/GetUnitUserData to store a unique integer on every unit in your map. Then you can just use the "GetUnitId" function to grab the ID. This is called unit indexing. You can look at UnitIndexingUtils or AutoIndex for that.

Table looks nice, though I don't understan squat of it I'm not that advanced yet.
However, the UnitIndexingUtils uses GetUnitUserData which I already explained why I don't want, and AutoIndex is faaaaar to complex for me


If grim001's function works, I'll give him +rep and this can be considered solved.
If not, I'll just ask for more help (and post the code so you may better understand my problem).



: : EDIT : :
W000000T! It seems to wooooork!
I just need more testing and such, before I give my +rep away.
Thanks a lot you guys for help, and a special thanks to grim001.
__________________
I have no signature yet

Last edited by Cheezeman : 05-03-2009 at 09:02 AM.
Cheezeman is offline   Reply With Quote
Old 05-03-2009, 10:19 AM   #7
akolyt0r
In Flames
 
akolyt0r's Avatar
 
Join Date: Jan 2006
Posts: 1,153

Submissions (3)

akolyt0r has a spectacular aura about (120)

Default

that thing about H2I-HandleIndexes getting too high is affected by ALL units in the map, not just the units which are affected by the spell...
__________________
akolyt0r is offline   Reply With Quote
Old 05-03-2009, 10:47 AM   #8
Viikuna-
User
 
Viikuna-'s Avatar
 
Join Date: Feb 2009
Posts: 203

Viikuna- will become famous soon enough (44)Viikuna- will become famous soon enough (44)

Default

Table would probably be easiest one if you are planning to just submit some spells. Or then you could make some UnitId wrappers, so people can make it use any Unit Indexing system.

If this goes to your map, you should build somekind of UnitUserData based indexing thingy.
__________________
No Marlo, no game.

Last edited by Viikuna- : 05-03-2009 at 10:48 AM.
Viikuna- is offline   Reply With Quote
Old 05-03-2009, 12:14 PM   #9
MaD[Lion]
MaD Da ViNci
 
MaD[Lion]'s Avatar


Respected User
 
Join Date: Apr 2003
Posts: 1,699

Submissions (10)

MaD[Lion] is a jewel in the rough (225)MaD[Lion] is a jewel in the rough (225)MaD[Lion] is a jewel in the rough (225)MaD[Lion] is a jewel in the rough (225)

Default

if he know as much as u guys talk he wouldnt ask. Lol... How can make make indexing systems when he dunno a basic indexing H2I exists.

Just tell him wat system he need or answer specific to his question :P
__________________
Current Projects:
MaDOS (outdated)System for object movements & effects - NEW VERSION IS UNDER W.I.P
Cinematic SystemSystem for making better cinematics and with fancy effects
Timing SystemTiming system that simulates the usage of PolledWait just with 0.01 accuracy
MaD[Lion] is offline   Reply With Quote
Old 05-03-2009, 08:48 PM   #10
Cheezeman
User
 
Cheezeman's Avatar
 
Join Date: Apr 2009
Posts: 179

Cheezeman has little to show at this moment (1)

Default

Quote:
Originally Posted by MaD[Lion]
if he know as much as u guys talk he wouldnt ask. Lol... How can make make indexing systems when he dunno a basic indexing H2I exists.

Just tell him wat system he need or answer specific to his question :P
100% correct
I'm really new to this so giving me advanced solutions won't solve my issues.

- -

Anyway it works for now, but I think I'll implent it to some larger map to see if it bugs
__________________
I have no signature yet
Cheezeman is offline   Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off


All times are GMT. The time now is 12:01 AM.


Affiliates
The Hubb The JASS Vault Clan WEnW Campaign Creations Clan CBS GamesModding Flixreel Videos

Powered by vBulletin (Copyright ©2000 - 2017, Jelsoft Enterprises Ltd).
Hosted by www.OICcam.com
IT Support and Services provided by Executive IT Services