| 08-06-2008, 02:08 PM | #1 |
Heya, could anybody help me out please: I want to save some stuff via integers for my heroes using unit's custom value. So for example, is the hero in team 1 or team 2, is he ranged or melee etc. So I would like to set the custom data. Code:
1000 = team1 2000 = team2 1100 = team 1 and ranged 2200 = team 2 and ranged And so on.. But how can I check now if the units is ranged, how to get the 2nd number of the custom value or the last 2 numbers etc. Thanks for your help, Soki |
| 08-06-2008, 02:18 PM | #2 |
You could convert that to string, get the substring (2, 2) and convert that substring to an integer. Alternatively, there is a boolean condition for checking if a unit is melee or ranged which would probably simplify what you're doing |
| 08-06-2008, 03:51 PM | #3 |
If you're doing it in base ten with one digit per piece of information: Digit at position i = (number mod 10^i) / 10^(i-1) (this is using 1-based indexing of the digits) For example if you have 5264, digit 3 is: 5264 % 10^3 / 10^2 = 264 / 100 = 2 (use integer division) Ofcourse if all of your information is binary you could do it more space efficiently. |
| 08-06-2008, 04:09 PM | #4 |
Click the PUI link in my signature. |
| 08-06-2008, 11:23 PM | #5 |
Wow your info is really useful blubb, thanks a lot (+rep), I think this could be useful for more people or even a system. And Cohadar, I don't get how Pui is related to this, it only gives every unit on the map a unique number? Sorry im new at Jass. |
| 08-06-2008, 11:31 PM | #6 | |
Quote:
He means that you can use that unique number as an index in an array to store the properties. |
| 08-06-2008, 11:36 PM | #7 |
Ranged or melee is a unit type, I think. Whether it actually works or not is another matter. As to which team, that could be derived from the owning player most likely. Plus, if it's only one per player, it'd be a lot easier just to store the data in an array with the player's index as the array index. |
| 08-09-2008, 11:45 AM | #8 |
or could i just store a struct in custum value? wouldn't that be the best way? edit: this is not about checking if a unit is in team x or if it's ranged or melee, those were just examples. |
