Snippet Custom Custom Value

Weep

Godspeed to the sound of the pounding
Reaction score
400
Custom Custom Value
by Weep
Version 1.0​

I'm surprised I haven't seen anything like this posted. Maybe I just missed it.

-- General Information --
This snippet will encode/retrieve an integer, attached to a unit, using the unit's inclusion and exclusion in each index of a unit group array as binary bits.

This allows you to attach an integer value to a unit without using UnitUserData, which is used so often by spells and systems that it's hazardous to use it yourself due to risk of conflicts.

This snippet is probably obsoleted by hashtables in 1.24 (depending on speed), for those who can use them (read: not Mac users).

-- How To Implement --
  1. Be sure "Automatically create unknown variables while pasting trigger data" is enabled in the World Editor general preferences.
  2. Copy the trigger category "CustomCustomValue" from the demo map and paste it into your map. (Alternately: create an integer variable named Identifier_CustomCustomBits and a unit group array named Identifier_CustomCustomValue.)
  3. Copy the code into your map header (click on the map's name at the top of the trigger list).
  4. (optional) If you want to make the indexes unique to your system or spell, go into the variable editor and rename the variables Identifier_CustomCustomValue and Identifier_CustomCustomBits to have a unique name in place of "Identifier". Then change all instances of the text "Identifier" in the code you just pasted to what you wrote (a text editor with Find/Replace All makes this quite easy).

Now, write your code using Identifier_SetCustomUnitUserData(unit, integer) in place of SetUnitUserData(unit, integer), and Identifier_GetCustomUnitUserData(unit) in place of GetUnitUserData(unit).

  • Step 4 can probably be made easy-breezy with private variables in vJASS, but of course I can't use vJASS myself, so you get this instead.

-- Code --
JASS:
// Globals: group array udg_Identifier_CustomCustomValue
//          integer udg_Identifier_CustomCustomBits

function Identifier_GetCustomUnitUserData takes unit u returns integer
    local integer l = 1
    local integer r = 0
    if(udg_Identifier_CustomCustomBits > 1) then
        loop
            exitwhen l == udg_Identifier_CustomCustomBits
            if(udg_Identifier_CustomCustomValue[l] != null and IsUnitInGroup(u, udg_Identifier_CustomCustomValue[l])) then
                set r = r + R2I(Pow(2, l-1))
            endif
            set l = l + 1
        endloop
        if(udg_Identifier_CustomCustomValue[0] != null and IsUnitInGroup(u, udg_Identifier_CustomCustomValue[0])) then
            set r = (-1)*r
        endif
    endif
    return r
endfunction

function Identifier_SetCustomUnitUserData takes unit u, integer i returns nothing
    local integer l = 1
    if(udg_Identifier_CustomCustomValue[0] == null) then
        set udg_Identifier_CustomCustomValue[0] = CreateGroup()
    endif
    if(i < 0) then
        call GroupAddUnit(udg_Identifier_CustomCustomValue[0], u)
        set i = IAbsBJ(i)
    else
        call GroupRemoveUnit(udg_Identifier_CustomCustomValue[0], u)
    endif
    loop
        exitwhen i < 1
        if(udg_Identifier_CustomCustomValue[l] == null) then
            set udg_Identifier_CustomCustomValue[l] = CreateGroup()
        endif
        if(ModuloInteger(i, 2) == 1) then
            call GroupAddUnit(udg_Identifier_CustomCustomValue[l], u)
        else
            call GroupRemoveUnit(udg_Identifier_CustomCustomValue[l], u)
        endif
        set i = i/2
        set l = l + 1
    endloop
    if(udg_Identifier_CustomCustomBits < l) then
        set udg_Identifier_CustomCustomBits = l
    else
        loop
            exitwhen l == udg_Identifier_CustomCustomBits
            call GroupRemoveUnit(udg_Identifier_CustomCustomValue[l], u)
            set l = l + 1
        endloop
    endif
endfunction

-- Notes --
Speed of this snippet is untested. Speed of GetCustomUnitUserData is proportional with the number of bits needed to store the largest integer yet saved in the map session.

  • I have no idea how to benchmark things in WC3, so if someone could do so, I'd appreciate the information.

-- Credits --
Some code based on Dec2Bin (http://wc3jass.com/viewtopic.php?t=76) by Aiursrage2k.

Credit in your map not needed, but please include the README.

-- Version History --
1.0: First release.

--------------------------------------​

Comments regarding problems, improvements, or redundancy (or praise ;)) welcome.
 

Attachments

  • CCV Demo.w3x
    21.2 KB · Views: 191

Romek

Super Moderator
Reaction score
964
You could use H2I + Gamecache or GetHandleId + Hashtables.
The latter of which is probably the fastest - faster than this.

Trouble is, nobody actually needs things like this. What's the point in making a system that's an alternative to Custom Data, that does the exact same thing (with the exact same limitations)?

> This allows you to attach an integer value to a unit without using UnitUserData
Why would you want to do that? :p

It's be easy for indexing systems to use hashtables or gamecache, though they don't, as Custom Data is much faster and more convenient. There's also no reason as to why it shouldn't be used.
 

Weep

Godspeed to the sound of the pounding
Reaction score
400
You could use H2I + Gamecache or GetHandleId + Hashtables.
The latter of which is probably the fastest - faster than this.
The Mac version of the World Editor can't use the new natives in 1.24, and there's a good chance <return h, DoNothing(), return 0> will be disabled in an upcoming patch - a better chance than Blizzard updating the World Editor for Mac.

Don't game caches start bugging out once you've played enough different maps that use them, requiring you to go delete some file?

Trouble is, nobody actually needs things like this. What's the point in making a system that's an alternative to Custom Data, that does the exact same thing (with the exact same limitations)?
The exact same limitations? This lets you make your own unique index set for your system or spell.

> This allows you to attach an integer value to a unit without using UnitUserData
Why would you want to do that? :p
To co-exist with UnitUserData. I've helped a few people on the main forum so far who did not want a solution to their problem that used UnitUserData because they had imported something else that used it.

It's be easy for indexing systems to use hashtables or gamecache, though they don't, as Custom Data is much faster and more convenient. There's also no reason as to why it shouldn't be used.
It really seems self-evident to me: hashtables can't be implemented on Mac (though downloaded maps that use them will work) nor pre-1.24 (which some people seem to still use - I keep reading people mention something called "Garena"?), gamecache has its own problems (or so I think I've read), and there's only one UnitUserData to be shared by everything in a map.
 

Weep

Godspeed to the sound of the pounding
Reaction score
400
Bump. Can someone benchmark this, if only for curiosity's sake? :)
 

Jesus4Lyf

Good Idea™
Reaction score
397
Why? It's got to be one of the slowest attaching methods I've ever heard of.

I've thought about this before. I reached much the same conclusions as Romek.

When the unit dies, references persist in the groups also, don't they? Sounds bad. :p

As for those projects, they should use a universal indexing system of some sort (AIDS or PUI... or AutoIndex). Since you're on a mac, I'd say just custom write something, or rip off PUI and make it plain JASS.
 

Weep

Godspeed to the sound of the pounding
Reaction score
400
While is is appropriate that this is graveyarded, because this version does exhibit a progressive, significant slowdown as units decay (though I may update it at some point), I just wanted to link a few posts supporting the reason for my original attempt:

http://www.thehelper.net/forums/showpost.php?p=1117714&postcount=4
http://www.thehelper.net/forums/showpost.php?p=1117832&postcount=7

People who'd need a system like this would be a small minority (Mac users who haven't managed to build their project on the principle that custom value should only be used for general unit indexing), but it could be useful, still. :p
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • Ghan Ghan:
    Howdy
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?
  • The Helper The Helper:
    Happy Thursday!
    +1
  • Varine Varine:
    Crazy how much 3d printing has come in the last few years. Sad that it's not as easily modifiable though
  • Varine Varine:
    I bought an Ender 3 during the pandemic and tinkered with it all the time. Just bought a Sovol, not as easy. I'm trying to make it use a different nozzle because I have a fuck ton of Volcanos, and they use what is basically a modified volcano that is just a smidge longer, and almost every part on this thing needs to be redone to make it work
  • Varine Varine:
    Luckily I have a 3d printer for that, I guess. But it's ridiculous. The regular volcanos are 21mm, these Sovol versions are about 23.5mm
  • Varine Varine:
    So, 2.5mm longer. But the thing that measures the bed is about 1.5mm above the nozzle, so if I swap it with a volcano then I'm 1mm behind it. So cool, new bracket to swap that, but THEN the fan shroud to direct air at the part is ALSO going to be .5mm to low, and so I need to redo that, but by doing that it is a little bit off where it should be blowing and it's throwing it at the heating block instead of the part, and fuck man
  • Varine Varine:
    I didn't realize they designed this entire thing to NOT be modded. I would have just got a fucking Bambu if I knew that, the whole point was I could fuck with this. And no one else makes shit for Sovol so I have to go through them, and they have... interesting pricing models. So I have a new extruder altogether that I'm taking apart and going to just design a whole new one to use my nozzles. Dumb design.
  • Varine Varine:
    Can't just buy a new heatblock, you need to get a whole hotend - so block, heater cartridge, thermistor, heatbreak, and nozzle. And they put this fucking paste in there so I can't take the thermistor or cartridge out with any ease, that's 30 dollars. Or you can get the whole extrudor with the direct driver AND that heatblock for like 50, but you still can't get any of it to come apart
  • Varine Varine:
    Partsbuilt has individual parts I found but they're expensive. I think I can get bits swapped around and make this work with generic shit though
  • Ghan Ghan:
    Heard Houston got hit pretty bad by storms last night. Hope all is well with TH.
  • The Helper The Helper:
    Power back on finally - all is good here no damage
    +1
  • V-SNES V-SNES:
    Happy Friday!
    +1

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top