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

This value to another value, is that possible?

Status
Not open for further replies.
Level 9
Joined
Aug 7, 2009
Messages
380
Yep, I saw a custom script like this:
  • Custom script: set udg_Int = udg_UnitType
While... Int is an integer variable and UnitType is a unit type variable
So... my question is how does this works
and after this, what would Int integer's value?
Thanks
 
Level 28
Joined
Jan 26, 2007
Messages
4,789
There are 2 simple methods:

For the first one, you shouldn't really use the variable udg_UnitType, but rather udg_Unit (a unit variable).
Then it becomes this:
  • Custom script: set udg_Int = GetUnitTypeId( udg_Unit )
That will convert the unit's type to an integer :)
(The variable type "unittype" isn't used very often as integers provide more freedom, JASS-users almost never use unit types for that reason).


For the second, you need to seek out the Raw ID of the unit type in the object editor (pressing CTRL + D will allow you to do this).
Then you use this trigger:

  • Custom script: set udg_Int = 'Hfoo'
The example above is for a footman ('Hfoo' is the Raw ID of a footman, so it will convert that into an integer).
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,259
It works because GUI provides a fake typecast of integer for the object type variable types. Even though the variable is declared as "Unit Type" in GUI you are actually making an integer.

This is why some of the hashtable actions crash the editor. There is an actual type called ability that was never finished or removed before release. Due to bad design choices it confused the patch team into thinking that was the ability type in GUI. As it references an unsupported type not in GUI it crashes the editor.
 
Level 19
Joined
Aug 8, 2007
Messages
2,765
Yep, I saw a custom script like this:
  • Custom script: set udg_Int = udg_UnitType
While... Int is an integer variable and UnitType is a unit type variable
So... my question is how does this works
and after this, what would Int integer's value?
Thanks

What DrSuperGood said is correct. When your putting in a "unit type" variable in GUI, its really just an integer. You can also do this with some other things

  • Custom script : set udg_Int = H2I(udg_PlayerUnit)
H2I stands for Handle to Integer. A handle is anything in-game that is mass reproduced, such as units and destructibles.
 
Level 28
Joined
Jan 26, 2007
Messages
4,789
It works because GUI provides a fake typecast of integer for the object type variable types. Even though the variable is declared as "Unit Type" in GUI you are actually making an integer.
I actually didn't know that GUI had any typecasting, good to know. I was a bit confused because of that :p.


Oh, there's one more thing: the value of the integer.
It is formed like this:

A unit type consists of 4 characters (such as 'Hfoo' for a footman), these are all ASCII characters.
So you've got a 4-character code ( 'n1 n2 n3 n4' ), you look up the ASCII code of those values (you can see that 2 equals 50 for example, use 50 as the number)
256³ * n1
+ 256² * n2
+ 256 * n3
+ 256° * n4 (this is just n4, as 256° equals 1)
= (integer)

An example: 'v9!s'
v = 118; 9 = 57; ! = 33; s = 115
(256³ * 118) + (256² * 57) + (256 * 33) + (115) = 1983455603.
So 'v9!s' will return that integer.
 
Level 9
Joined
Aug 7, 2009
Messages
380
Wow,... they all go wild, still can't believe that I understood them all - lol
So, can I say this:
Unit's Raw Code = Unit Type ID =
  • Custom script: set udg_Int = udg_UnitType
Cool :D, but too complicated. But some more questions:
When i want to store a (some) values as the unit's type ID that means this will apply to all units with the same rawcode (unit type ID)?

thanks alot, +rep all for answering the 1st question :ogre_haosis:
 
Level 28
Joined
Jan 26, 2007
Messages
4,789
But some more questions:
When i want to store a (some) values as the unit's type ID that means this will apply to all units with the same rawcode (unit type ID)?
It will save for all units of the same type indeed. Sometimes that is desired :p

If you want it to save for a single unit (instead of unit type), you can get the Id of the unit (which is a unique ID, different from all other units that will be on the map) with "GetHandleId( udg_Unit )".
 
Level 20
Joined
Jul 6, 2009
Messages
1,885
Wait, what? I talking about unit type variables, never said it was a rawcode (which, according to me, are things like 'a001'. Something else I am missing?
JASS-users almost never use unit types for that reason)

Unit type variables in GUI and rawcodes are both integers.

I just wanted to point out the use of "unittype" type since you mentioned it. There's no type (variable) in Jass that holds unit type other than integers.
 
Level 28
Joined
Jan 26, 2007
Messages
4,789
But unit type variables should contain rawcodes and are as such, integers.

I just wanted to point out the use of "unittype" type since you mentioned it. There's no type in Jass that holds unit type other than integers.
Oh, okay. Thanks for the heads-up then :D
Aren't you able to do local unittype ut = ConvertUnitType( 'a000' ) though? (That was pretty much my point: nobody uses that).
 
Level 20
Joined
Jul 6, 2009
Messages
1,885
Oh, okay. Thanks for the heads-up then :D
Aren't you able to do local unittype ut = ConvertUnitType( 'a000' ) though? (That was pretty much my point: nobody uses that).

ConvertUnitType doesn't take rawcode as the argument, it takes an integer between 0-26 which are existing unit classifications.
local unittype ut = ConvertUnitType( 'a000' ) would return an invalid unittype.

Unit classification is named unittype in Jass, apparently. (Blizzard making sense :con:)
 
Level 28
Joined
Jan 26, 2007
Messages
4,789
ConvertUnitType doesn't take rawcode as the argument, it takes an integer between 0-26 which are existing unit classifications.
local unittype ut = ConvertUnitType( 'a000' ) would return an invalid unittype.

Unit classification is named unittype in Jass, apparently. (Blizzard making sense :con:)
Aha! Now it makes perfect sense :D Thanks for the info.
 
Status
Not open for further replies.
Top