Snippet JIS - Jass Indexing Snippet

GetTriggerUnit-

DogEntrepreneur
Reaction score
129
JIS - Jass Indexing Snippet
by GetTriggerUnit-

What is it?​
- JIS is an indexing system that set the custom value of every unit entering the map automaticly. When a unit die or is removed, it custom value is recycled and re-used.
- It can store a maximum of 8190 unit at a time on a
- It's leakless, lagless and MUI of course.​

How does it work?​
-Simply use the custom value of a unit
-Do not set the custom value of a unit, it's done automaticly
-When a unit die, it automaticly recycle it value.

Why use this one instead of another?

At start, I have made this one for the ones that can't / do not , want to use NewGen. It work like anyother system indexing system, without any requirement.
Code
JASS:

//--------------------------------------------------------------------------------------------+
//   JIS - Jass Indexing Snippet                                                              |
//                                                                                            |
// What is it?                                                                                |
//          - JIS is an indexing system that set the custom value of every unit entering the  |
//          map automaticly. When a unit die or is removed, it custom value is recycled and   |
//          re-used.                                                                          |
//          - It can store a maximum of 8190 unit at a time on a map.                         |
//          - It's leakless, lagless and MUI of course.                                       |
//                                                                                            |
// How to use?                                                                                |
//          - Simply use "Custom value of unit" Jass(GetUnitUserData)                         |
//          - Do not set the custom value, the value locking part is not done yet.            |
//                                                                                            |
// Why use it?                                                                                |
//          - To avoid sereval units to have the custom value. In a spell, if you use the     |
//          Mui count, 2 units may end-up with the same value. If there's many spells/systems |
//          using custom values running at a same time, it can bug. With this, simply use     |
//          custom value without setting it. If you set it, it might bug.                     |
//                                                                                            |
// How to Implement?                                                                          |
//          - Create a new trigger called JSI, paste all this script code in, and create a    |
//          global variable called JIS_Recycle of type boolean and array                      |
//                                                                                            |
//--------------------------------------------------------------------------------------------+

function JIS_OnInit takes nothing returns nothing
    local integer count = 0
    local integer start = 0
    local group g = CreateGroup()
    local unit u
    loop
        set start = start + 1
        set udg_JIS_Recycle[start] = false
        exitwhen start == 8190
    endloop
    call GroupEnumUnitsInRect(g, GetPlayableMapRect(), null)
    loop
        set u = FirstOfGroup(g)
        exitwhen u == null
        set count = count + 1
        set udg_JIS_Recycle[count] = true
        call SetUnitUserData(u, count)
        call GroupRemoveUnit(g, u)
    endloop
    call DestroyGroup(g)
endfunction

function JIS_OnCreate takes nothing returns nothing
    local integer count = 0
    loop
        set count = count + 1
        if udg_JIS_Recycle[count] == false then
            call SetUnitUserData(GetTriggerUnit(), count)
            set udg_JIS_Recycle[count] = true
            return
        endif
        exitwhen count == 8190
    endloop
endfunction

function JIS_Filter takes nothing returns boolean
    return (GetUnitUserData(GetFilterUnit()) == GetForLoopIndexA())
endfunction

function JIS_OnRemove takes nothing returns nothing
        local group g
        local unit u
        set bj_forLoopAIndex = 0
        loop
            set g = CreateGroup()
            set bj_forLoopAIndex = bj_forLoopAIndex + 1
            if udg_JIS_Recycle[bj_forLoopAIndex] == true then
                call GroupEnumUnitsInRect(g, GetPlayableMapRect(), Condition(function JIS_Filter))
                if CountUnitsInGroup(g) == 0 then
                    set udg_JIS_Recycle[bj_forLoopAIndex] = false
                endif
            endif
            call DestroyGroup(g)
            exitwhen bj_forLoopAIndex == 8190
        endloop
        call DestroyGroup(g)
endfunction

// Init function

function InitTrig_JIS takes nothing returns nothing
    local trigger t = CreateTrigger()
    call TriggerAddAction(t, function JIS_OnInit)
    call TriggerRegisterTimerEventSingle(t, 0.00)
        
    set t = CreateTrigger()
    call TriggerRegisterEnterRectSimple(t, GetPlayableMapRect())
    call TriggerAddAction(t, function JIS_OnCreate)
        
    set t = CreateTrigger()
    call TriggerRegisterTimerEventPeriodic(t, 0.25)
    call TriggerAddAction(t, function JIS_OnRemove)
endfunction
 

Azlier

Old World Ghost
Reaction score
461
Is there any reason at all to use this over AIDS, especially with this being less efficient and less useful?
 

Viikuna

No Marlo no game.
Reaction score
265
Your group usage is bad and it leaks.

Index should be recycled when unit is removed from the game, not before that. ( Note that some units can decay )


This doesn't not require vJass. I guess that it's a very good argument.

Its other way around. Systems should require vJass.
 

GetTriggerUnit-

DogEntrepreneur
Reaction score
129
So I should Remove the function OnDeath and keep the function OnRemove?

Oh just saw these leaks, my bad. Correcting it now.<

New Code
JASS:

//--------------------------------------------------------------------------------------------+
//   JIS - Jass Indexing Snippet                                                              |
//                                                                                            |
// What is it?                                                                                |
//          - JIS is an indexing system that set the custom value of every unit entering the  |
//          map automaticly. When a unit die or is removed, it custom value is recycled and   |
//          re-used.                                                                          |
//          - It can store a maximum of 8190 unit at a time on a map.                         |
//          - It&#039;s leakless, lagless and MUI of course.                                       |
//                                                                                            |
// How to use?                                                                                |
//          - Simply use &quot;Custom value of unit&quot; Jass(GetUnitUserData)                         |
//          - Do not set the custom value, the value locking part is not done yet.            |
//                                                                                            |
// Why use it?                                                                                |
//          - To avoid sereval units to have the custom value. In a spell, if you use the     |
//          Mui count, 2 units may end-up with the same value. If there&#039;s many spells/systems |
//          using custom values running at a same time, it can bug. With this, simply use     |
//          custom value without setting it. If you set it, it might bug.                     |
//                                                                                            |
// How to Implement?                                                                          |
//          - Create a new trigger called JSI, paste all this script code in, and create a    |
//          global variable called JSI_Recycle of type boolean and array                      |
//                                                                                            |
//--------------------------------------------------------------------------------------------+

function JIS_OnInit takes nothing returns nothing
    local integer count = 0
    local integer start = 0
    local group g = CreateGroup()
    local unit u
    loop
	set start = start + 1
	set udg_JIS_Recycle[start] = false
	exitwhen start == 8190
    endloop
    call GroupEnumUnitsInRect(g, GetPlayableMapRect(), null)
    loop
	set u = FirstOfGroup(g)
	exitwhen u == null
	set count = count + 1
	set udg_JIS_Recycle[count] = true
	call SetUnitUserData(u, count)
	call GroupRemoveUnit(g, u)
    endloop
    call DestroyGroup(g)
endfunction

function JIS_OnCreate takes nothing returns nothing
    local integer count = 0
    loop
	set count = count + 1
	if udg_JIS_Recycle[count] == false then
	    call SetUnitUserData(GetTriggerUnit(), count)
	    set udg_JIS_Recycle[count] = true
	    return
        endif
        exitwhen count == 8190
    endloop
endfunction

function JIS_Filter takes nothing returns boolean
    return (GetUnitUserData(GetFilterUnit()) == GetForLoopIndexA())
endfunction

function JIS_OnRemove takes nothing returns nothing
	local group g
	local unit u
	set bj_forLoopAIndex = 0
	loop
            set g = CreateGroup()
	    set bj_forLoopAIndex = bj_forLoopAIndex + 1
	    if udg_JIS_Recycle[bj_forLoopAIndex] == true then
                call GroupEnumUnitsInRect(g, GetPlayableMapRect(), Condition(function JIS_Filter))
                if CountUnitsInGroup(g) == 0 then
                    set udg_JIS_Recycle[bj_forLoopAIndex] = false
                endif
	    endif
            call DestroyGroup(g)
	    exitwhen bj_forLoopAIndex == 8190
	endloop
	call DestroyGroup(g)
endfunction

// Init function

function InitTrig_JIS takes nothing returns nothing
    local trigger t = CreateTrigger()
    call TriggerAddAction(t, function JIS_OnInit)
    call TriggerRegisterTimerEventSingle(t, 0.00)
	
    set t = CreateTrigger()
    call TriggerRegisterEnterRectSimple(t, GetPlayableMapRect())
    call TriggerAddAction(t, function JIS_OnCreate)
	
    set t = CreateTrigger()
    call TriggerRegisterTimerEventPeriodic(t, 0.25)
    call TriggerAddAction(t, function JIS_OnRemove)
endfunction
 

Weep

Godspeed to the sound of the pounding
Reaction score
400
Its other way around. Systems should require vJass.
That's terrible. It automatically prevents Mac mappers from being able to implement the system in question. Not requiring vJass/NewGen is a great feature. :thup:

(No comment on how well this particular system works; I haven't looked it over yet.)
 

trb92

Throwing science at the wall to see what sticks
Reaction score
142
In documentation:
JASS:
//          create a
//          global variable called JSI_Recycle of type boolean and array


In code
JASS:
set udg_JIS_Recycle[count] = true
[...]
if udg_JIS_Recycle[count] == false then
            call SetUnitUserData(GetTriggerUnit(), count)
            set udg_JIS_Recycle[count] = true


Those variable names need to line up. JIS_Recycle might be used again, I don't know. Didn't look through the entire code. This is just from the first two functions
 

Jesus4Lyf

Good Idea™
Reaction score
397
This is absurd. I could write better in GUI.
JASS:
function JIS_OnRemove takes nothing returns nothing
        local group g
        local unit u
        set bj_forLoopAIndex = 0
        loop
            set g = CreateGroup()
            set bj_forLoopAIndex = bj_forLoopAIndex + 1
            if udg_JIS_Recycle[bj_forLoopAIndex] == true then
                call GroupEnumUnitsInRect(g, GetPlayableMapRect(), Condition(function JIS_Filter))
                if CountUnitsInGroup(g) == 0 then
                    set udg_JIS_Recycle[bj_forLoopAIndex] = false
                endif
            endif
            call DestroyGroup(g)
            exitwhen bj_forLoopAIndex == 8190
        endloop
        call DestroyGroup(g)
endfunction

Hey GUI users, we have an O(n^2) complexity indexing system for you! Instead of GetHandleId and hashtables!

Sorry Blitz, this isn't useful. :(

PS. This doesn't for locusted units either.
 

Viikuna

No Marlo no game.
Reaction score
265
Hrm, yea, I forgot mac users...

But yea, it kinda depends. If you do systems for mac users they should ofc be normal Jass, but then again people who can use vJass are less likely to use them.

And your groups are still leaking because:


1) GroupEnum with temporary group leaks.

2) GroupEnum with null boolexprs leaks.

3) Not nulling a local pointing to some temporaty group also leaks.

Solution: Create one global group in map init and use it for all GroupEnums and do your actions in filterfunctions.

( Someone should really write some group tutorial... )
 

kingkingyyk3

Visitor (Welcome to the Jungle, Baby!)
Reaction score
216
How about this..

JASS:
//Variables needed :
// an integer named JIS_Counter
// an integer named JIS_ReCount
// an integer array named JIS_ReIndex


JASS:
function JIS_InFilter takes nothing returns boolean
    return GetUnitUserData(GetTriggerUnit()) == 0 and GetUnitAbilityLevel(GetTriggerUnit(),&#039;Aloc&#039;) == 0
endfunction

function JIS_OutFilter takes nothing returns boolean
    return GetUnitUserData(GetTriggerUnit()) &gt; 0
endfunction

function JIS_IndexUnit takes nothing returns nothing
    if JIS_ReCount &gt; 0 then
        call SetUnitUserData(GetTriggerUnit(),JIS_ReIndex[JIS_ReCount])
        set JIS_ReCount = JIS_ReCount - 1
        return
    else
        set JIS_Counter = JIS_Counter + 1
        call SetUnitUserData(GetTriggerUnit(),JIS_Counter)
    endif
endfunction

function JIS_RemoveIndex takes nothing returns nothing
    set JIS_ReCount = JIS_ReCount + 1
    set JIS_ReIndex[JIS_ReCount] = GetUnitUserData(GetTriggerUnit())
endfunction

function InitTrig_JIS takes nothing returns nothing
    local trigger t
    local region playable = CreateRegion()
    
    set t = CreateTrigger()
    call RegionAddRect(playable,bj_mapInitialPlayableArea)
    call TriggerRegisterEnterRegion(t,playable,Condition(function JIS_InFilter))
    call TriggerAddAction(t,function JIS_IndexUnit)
    
    set t = CreateTrigger()
    call TriggerRegisterLeaveRegion(t,playable,Condition(function JIS_OutFilter))
    call TriggerAddAction(t,function JIS_RemoveIndex)
endfunction
 

kingkingyyk3

Visitor (Welcome to the Jungle, Baby!)
Reaction score
216
Tested :
Trigger:
  • Untitled Trigger 001
    • Events
      • Player - Player 1 (Red) types a chat message containing -test as An exact match
    • Conditions
    • Actions
      • Do Multiple ActionsFor each (Integer A) from 1 to 8191, do (Actions)
        • Loop - Actions
          • Game - Display to (All players) the text: (String((Integer A)))


Last number it showed was 6250

JASS:
    local integer i = 1
    loop
    exitwhen i == 8191
        call DisplayTextToPlayer(Player(0),0,0,I2S(i))
        set i = i + 1
    endloop


This can reach max number..
 

T.s.e

Wish I was old and a little sentimental
Reaction score
133
And yet another one reinvents the broken wheel.
 

Gtam

Lerning how to write and read!! Yeah.
Reaction score
164
Fact. there is a GUI MUI system for GUIers and all the jassers i know has NEWGEN so where does this fit in??? GUIers wont use it. Jassers will use AIDS or PUI
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • 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
    +2
  • V-SNES V-SNES:
    Happy Friday!
    +1
  • The Helper The Helper:
    New recipe is another summer dessert Berry and Peach Cheesecake - https://www.thehelper.net/threads/recipe-berry-and-peach-cheesecake.194169/
  • The Helper The Helper:
    I think we need to add something to the bottom of the front page that shows the Headline News forum that has a link to go to the News Forum Index so people can see there is more news. Do you guys see what I am saying, lets say you read all the articles on the front page and you get to the end and it just ends, no kind of link for MOAR!
  • The Helper The Helper:
    Happy Wednesday!
    +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