Warcraft III resources & community, 2003–2006 · archived

Custom value

15 posts
#1

Custom value

Is there a way to assign custom value of unit other type than integer (string will be the most useful)?
#2
No. you can do stuff like this with some really complicated JASS, etc, etc, but i wont go into that, as you wouldnt understand it.
#3
I was thinking to create global variable first for each preplaced unit and then for each unit trained/ressurected. Of course it will need to clear it after unit dies. However, the variable will need a pointer to it.
#4
well, i dont see how you would do that, as global variables need predefining.

Just store the variable's reference in a gamecache under that unit?
#5
So global variables cannot be declared and cleared during execution of program in JASS?
#6
No, they have to be defined at the start, in a special

globals
    [...]
endglobals


block, that the WE generates from your Variable list ( Ctrl-B ) at the start. you cannot have more than one of that block.
#7
unless you will have more then 8000 units in your map you could do this:
you will need 1 integer variable(Current) and one string array(SomeData).
when a unit enters map set its custom value to "Current" and then increase "Current" by one.
Unit - Set custom value of unit to Current
Set Current = Current + 1

Then when you want to access/store string data to that units you use
set blablastring = SomeData[Custom Value of blablaunit)]

this only works for somewhere near 8000 units thou (dont remember the exact number but I think it's 8192)
#8
Try this (I have no idea, if it works):

function CastS2I takes String s returns integer
  return s
  return 0
endfunction

call SetUnitUserData( <unit> , CastS2I( <String> ))

function CastI2S takes integer i returns string
  return i
  return ""
endfunction

  set <String> = CastI2S(GetUnitUserData( <unit> ))
#9
I doubt it will work, as it has two return statements.
#10
that is called the "return bug"

a function is left, once the first return statement is hit.
The script-compiler only checks wether the last return statement has the type, that the function shall return.
That means, tht when the first return statement is hit, an invalid type is returned. but wc3 does not crash becouse of that, but converts the type into the type the function shall return.

i doubt that this will work nevertheless. But for another reason:
if you have the string "abcd" and convert it into integer, normaly the ASCII-Value of each character is used for this. then there are 2 possibilities for the result: "41 42 43 44" simply put onw after another.
the other possibility would be the summ of the chars, in this case "170" - the first way might be converted backwards, the second one not. (it would return char with ID #17 and char with ID #0, or simply invalid, means "null")

in the first case, wich is, as i believe, used, you have another problem:
the max integer size is about 11 places, means you can store up to 5(5*2=10<11) chars in it...
i doubt that this will be enough for you.

if it were this easy, only very few people would mess around with the gameCache...

- Raszul
#11
Should not the physical adress of the object be returned this way?
How else may a unit be stored without being removed?
(If you convert a unit into a real, the unit should vanish, if the object type is casted... But then this whole thing "handle vars" would not work, would it?)
#12
LordZsar1Try this (I have no idea, if it works):

function CastS2I takes String s returns integer
  return s
  return 0
endfunction

call SetUnitUserData( <unit> , CastS2I( <String> ))

function CastI2S takes integer i returns string
  return i
  return ""
endfunction

  set <String> = CastI2S(GetUnitUserData( <unit> ))


I see no reason for a custom I2S when there already is one in the common.j?
(btw its string s and not String s)
#13
Oops. ^^
Yes, that is right. I forgot this native function.

Btw... Did it work?
#14
nope it doesnt work.
A string that cannot be translated into an integer gets converted to 0.
#15
im pretty sure www.wc3jass.com has an ASCIICharToInt function, but it seems to be down atm, so i cant get a link :?