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.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top