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

[JASS] Custom value

Status
Not open for further replies.
Level 6
Joined
May 19, 2004
Messages
267
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)
 
Level 5
Joined
May 22, 2006
Messages
150
Try this (I have no idea, if it works):

JASS:
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> ))
 
Level 6
Joined
Feb 18, 2005
Messages
263
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
 
Level 5
Joined
May 22, 2006
Messages
150
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?)
 
Level 6
Joined
May 19, 2004
Messages
267
LordZsar1 said:
Try this (I have no idea, if it works):

JASS:
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)
 
Status
Not open for further replies.
Top