System Advanced Indexing & Data Storage

Nerzhul

New Member
Reaction score
7
I Mean, I need to attach lot of data for EACH creep in the map but with many variables with big arrays it cause corruption.Is there a way with AIDS to solve that?
 

Azlier

Old World Ghost
Reaction score
461
Yes, AIDS makes unit attachment easy. And efficient.

Anyway, are you trying to create a big stack of arrays with size 1000 or something? That won't make it past map initialization. Set array size to 0, you can still use all the indices up to 8191.
 

Jesus4Lyf

Good Idea™
Reaction score
397
If you have AIDS in your map and want to attach to units from GUI, use Get Unit's Custom Value (make sure you NEVER use set unit's custom value though).

That will return a unique number for that unit from 1 to 8191. So you can use that for an array index. (This is actually how AIDS structs work anyway.)
 

Jesus4Lyf

Good Idea™
Reaction score
397
Sorry for the delay.
I'm creating an aggro system and I was wondering if the following snippet correctly assigns an index and setup up aggro-related stuff for a unit:
In AIDS, you do not need to have the "[LJASS]unit source[/LJASS]" member, as AIDS provides you with a member: [LJASS].unit[/LJASS]. This is the unit for which the struct exists.
Also, I have a spell that bestows a debuff on an enemy unit. Everytime the enemy unit casts a spell it takes damage. However, I have to know the source of the spell (the caster) to properly deal damage so that the source gets the bounty for the kill, if the target dies.

Would you then use the index of the unit as an index for a specific array of structs that the spell uses?
I would not use unit attaching at all for this. What you need is a stand-alone struct, with a trigger (which you register for when that unit casts a spell) and you need to attach the casting unit to that trigger (by attaching the struct). Destroy the struct and the trigger after x seconds using a timer (timer system of some sort). Hope you get what I mean.

>But if you use GetWorldBounds instead of bj_mapInitialPlayableArea, it will have less checks.
I'll address this soon enough. When I find time with WC3.
This was actually on my list of things to add.

I believe that's all questions answered, if I missed anything or any more information is needed, please ask. :)
 

Embrace_It

New Member
Reaction score
9
Great explantion! :thup: Just what I needed to know.

I would not use unit attaching at all for this. What you need is a stand-alone struct, with a trigger (which you register for when that unit casts a spell) and you need to attach the casting unit to that trigger (by attaching the struct). Destroy the struct and the trigger after x seconds using a timer (timer system of some sort). Hope you get what I mean.

Just to be clear, this is what you mean:

JASS:

private struct Data
   unit source
   unit target
   real damage
   trigger dealdamage // Registered in the create method
   
   ...

endstruct


I thought up another question meanwhile :D:

If you have two or more systems in your map that need AIDS, can you use it for both? Even though the structs and such are completely different?

Thanks!
 

Troll-Brain

You can change this now in User CP.
Reaction score
85
I just want to point in fact you have to check if the unit is already indexed or not, since you can put the unit outside the entire map ( GetWorldBounds() ) without making war3 crash (should be pointless though, and is definitely possible source of crash).

But since it's possible to fix it, in a reasonable efficient and easy way, you should do it.
 

Jesus4Lyf

Good Idea™
Reaction score
397
>But since it's possible to fix it, in a reasonable efficient and easy way, you should do it.
Absolutely. As said, will be in next update. Be patient with me, I have limited WC3 time. It will be done. :)

>If you have two or more systems in your map that need AIDS, can you use it for both? Even though the structs and such are completely different?
Absolutely! You can have as many different AIDS structs as you like. For the same units, or not. The system is incredibly flexible:
You can even typecast between AIDS structs for the same unit. :thup:

@Embrace_It
Yes, that's what I mean. And find a system of choice to attach that struct to the trigger, and make the trigger fire when the target casts a spell... :)
 

SanKakU

Member
Reaction score
21
You mean...
JASS:
struct CreepRevival extends array
    //! runtextmacro AIDS()
    private trigger t
    private real x
    private real y
    private integer utype
    
    private static method OnDeath takes nothing returns nothing
        local thistype d=thistype[GetTriggerUnit()]
        
        // Because the struct may be destroyed before the wait finishes.
        local trigger t=d.t
        local real x=d.x
        local real y=d.y
        local integer utype=d.utype
        set d.t=null
        
        call TriggerSleepAction(3.0)
        call CreateUnit(Player(PLAYER_NEUTRAL_AGGRESSIVE),utype,x,y,0)
        call DestroyTrigger(t)
        set t=null
    endmethod
    
    private static method AIDS_filter takes unit u returns boolean
        return GetOwningPlayer(u)==Player(PLAYER_NEUTRAL_AGGRESSIVE)
    endmethod
    private method AIDS_onCreate takes nothing returns nothing
        set this.utype=GetUnitTypeId(this.unit)
        set this.x=GetUnitX(this.unit)
        set this.y=GetUnitY(this.unit)
        
        set this.t=CreateTrigger()
        call TriggerAddAction(this.t,function thistype.OnDeath)
        call TriggerRegisterUnitEvent(this.t,this.unit, EVENT_UNIT_DEATH )
    endmethod
endstruct
? :D

I kinda had to. For each unit owned by neutral hostile, that will store its x/y/type, and on death wait 3.0 seconds and then spawn a new unit of that type at that original x and y, regardless where it died. Change 3.0 to your liking. This is why I made AIDS... It makes map-wide unit data systems sooo easy to code. <_<

Edit: I may add something called Locks (which won't break anything currently made) which will stop an index from being freed (and hence all AIDS structs on it) until the same number of Unlocks have been called. :)

... So, you'd be able to attach the struct to a timer, and not worry about it getting destroyed, because it won't be until the timer unlocks it after its callback... (Which is what I should've done here, not that it matters.)

Edit again:
In answer to your question, I'd recommend you give your map AIDS.

just curious, why is triggersleepaction used instead of a timer like from KT2? is it just because doing so would complicate the code further?

edit: after looking at your system a bit and your example of creeprevival i think i can figure out how to do what i asked you about in that private message earlier with your code...thanks.

finally i got something practical to work with in structs...i guess i'm one step closer to understanding them.

edit2: oh wow i must be tired! what did i just type in there? i have no idea how to use a timer...lol...but i'm a lot closer to learning structs so i guess i can forget about timers for now...
 

Jesus4Lyf

Good Idea™
Reaction score
397
Don't worry, I made this version just to confuse the frak out of innocent JASSers like yourself! :D

It's a few posts down, and is much better...
So for Renendaru, here's a AIDS/KT version of a simple creep respawn system. You could even add an AIDS_onDestroy so if creeps were REMOVED from the game, they'd STILL respawn. XD
JASS:
struct CreepRevival extends array
    //! runtextmacro AIDS()
    private trigger t
    private real x
    private real y
    private integer utype
    
    private static method Callback takes nothing returns boolean
        local thistype this=KT_GetData()
        call CreateUnit(Player(PLAYER_NEUTRAL_AGGRESSIVE),this.utype,this.x,this.y,0)
        call this.AIDS_removeLock()
        return true
    endmethod
    
    private static method OnDeath takes nothing returns boolean
        local thistype this=thistype[GetTriggerUnit()]
        call this.AIDS_addLock() // So the struct can&#039;t disappear before the timer ticks.
        call KT_Add(function thistype.Callback,this,3.0)
        call DestroyTrigger(this.t)
        set this.t=null
        return false
    endmethod
    
    private static method AIDS_filter takes unit u returns boolean
        return GetOwningPlayer(u)==Player(PLAYER_NEUTRAL_AGGRESSIVE)
    endmethod
    private method AIDS_onCreate takes nothing returns nothing
        set this.utype=GetUnitTypeId(this.unit)
        set this.x=GetUnitX(this.unit)
        set this.y=GetUnitY(this.unit)
        
        set this.t=CreateTrigger()
        call TriggerAddCondition(this.t,Condition(function thistype.OnDeath))
        call TriggerRegisterUnitEvent(this.t,this.unit, EVENT_UNIT_DEATH )
    endmethod
endstruct
PS. The previous version leaked trigger actions, I forgot. lol.
 

SanKakU

Member
Reaction score
21
Don't worry, I made this version just to confuse the frak out of innocent JASSers like yourself! :D

It's a few posts down, and is much better...

and..."PS. The previous version leaked trigger actions, I forgot. lol."

ahhh...oh of course it did! lol...

yeah i gotta study more...
 

black.sheep

Active Member
Reaction score
24
Would it be possible to make a "saftey" version of this for people who dont wanna go back and redo all the Custom Value triggers with a dummy ability with +1000 levels?
(If its even possible to get over that)
 

Viikuna

No Marlo no game.
Reaction score
265
The main complication is AIDS struct locking (something AutoIndex lacks to the best of my knowledge ).

These locks?

JASS:
Locks just
//            put off AIDS struct destruction in case you wish to attach to a timer
//            or something which must expire before the struct data disappears.
//            Hence, not freeing all locks will leak the struct (and index).


So it just prevents AIDS from recycling AIDS struct instance and giving it to some new unit, right?

I see that it is useful with AIDS structs, but the thing is different with AutoIndex, because it has no AIDS struct like thingies.
It simple recycles index when unit is removed from the game, since you dont really need to keep index for some non existing unit. ( At leats I cant think any reason to do so )

Hrm. I was sure I had some point I wanted to say, but I forgot it.
 

Troll-Brain

You can change this now in User CP.
Reaction score
85
Hrm. I was sure I had some point I wanted to say, but I forgot it.
Some limitations caused by the need of an array struct like not possible to have array members, maybe ?
 

Jesus4Lyf

Good Idea™
Reaction score
397
>But since it's possible to fix it, in a reasonable efficient and easy way, you should do it.
Absolutely. As said, will be in next update. Be patient with me, I have limited WC3 time. It will be done. :)
Done. Now uses [LJASS]GetWorldBounds()[/LJASS] and checks that the unit's userdata is 0. (Version 1.0.4 released.)
 
Reaction score
456
Suggestion: Use structs onInit method instead of library initializer to initialize AIDS :p.
 

Romek

Super Moderator
Reaction score
963
So that you can use a units index in a struct initializer.

Struct initializers fire in the order they appear in the maps script.
So libraries get priority, and using [ljass]requires[/ljass] will make it run before other libraries.
 

Jesus4Lyf

Good Idea™
Reaction score
397
Just released 1.1.0 which features undefend removal detection (O(1) complexity).

I like periodic removal better. There is a constant. Flick the switch. Default is undefend removal (seems to be fashionable).

The relative order between different struct initializers depends on the location they are found in the map script, therefore they actually depend on things like libraries as well (A struct initializer inside a library will run before the initializers inside other libraries that require it and also before initializers inside scopes).
Hm. I'll use a struct initialiser then, and release an update.

Edit: Actually, AIDS initialisation needs to fire after all structs. The structs onInit is used to fill AIDS with a list of structs to create/destroy for units on indexing, so the AIDS init which starts indexing units needs to fire after struct onInits. :)
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      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