AIDS structre question

W!†A_cRaft

Ultra Cool Member
Reaction score
28
If i make a structure and make it an AIDS struct like this:

JASS:

struct random_name extends array
//!   runtextmacro AIDS()
      public integer number
      static method AIDS_filter takes unit u returns boolean
            if (u == udg_myhero)then
                  return true
            endif
            return false
      endmethod
endstruct


Now if i have some other trigger, in which i need to access the data stored in the unit's struct, how do i reference myself to the structure?

I've read in the documentation:
JASS:

//          - The structs id will be the units index, so getting the struct for
//            a unit inlines to a single native call, and you can typecast between
//            different AIDS structs. This is the premise of AIDS.


but i dont understand how to get the specific structure if i have it's unit?
 

luorax

Invasion in Duskwood
Reaction score
67
JASS:
<struct_name>[whichUnit].member_name


As i remember.

An example:

JASS:
local unit u = CUS[whichUnit].getLastAttackTarget()
local real dmg = CUS[whichUnit].damage


EDIT: oh, sorry, this doesn't returns the struct itself.
 

W!†A_cRaft

Ultra Cool Member
Reaction score
28
okay i do not understand you :p

take a look at what i did:
JASS:
    struct Champion extends array
        //! runtextmacro AIDS()
        //========================================================
        //Filter is used to make sure that only hero units owned by players recieve
        //a structure of this type, since units and bossess have static attributes
        private real coefficient
        static method AIDS_filter takes unit u returns boolean
            if (GetPlayerController(GetOwningPlayer(u)) == MAP_CONTROL_USER) and (IsUnitType(u, UNIT_TYPE_HERO))then
                return true
            else
            endif
            return false
        endmethod


now, i have this other function in which i need to set the coeficient field of my struct to a different value:

JASS:
    private function ondamage_actions takes nothing returns nothing
        local unit u = GetEventDamageSource()
        local real dmg = GetEventDamage()
        local unit target = GetTriggerUnit()
        //now i need to set the coefficient field of a structure Champion
        //created for unit u to a number such as 1.45
    endfunction


Only heroes have this coefficient and it is dynamic so that is why i need to change it. However, i don't know how to do that....

Do i need to do something like:
JASS:
local Champion hero = Champion[GetUnitId(u)]
set hero.coefficient = 1.45


EDIT: I need the structure returned or placed into a local variable so that i can access the data that is inside of it.
 

luorax

Invasion in Duskwood
Reaction score
67

Laiev

Hey Listen!!
Reaction score
188
JASS:
struct random_name extends array
//! runtextmacro AIDS()
    public integer number
    static method AIDS_filter takes unit u returns boolean
        return u == udg_myhero
    endmethod

    method getStruct takes nothing returns thistype
        return thistype
    endmethod
endstruct


function test takes nothing returns nothing
    local integer Struct = random_name[Unit].getStruct()
    //if i'm not wrong, it will return some number if the Unit pass to the filter, else will return 0
endfunction
 

Ashlebede

New Member
Reaction score
43
[ljass]return thistype[/ljass]

Is not a correct syntax. It's like saying :

[ljass]return unit[/ljass]
or
[ljass]return real[/ljass].

[ljass]return this[/ljass] would be a correct syntax.

And you should use [ljass]local random_name Struct[/ljass] instead of [ljass]local integer Struct[/ljass]. I actually never tried, but I don't think you can reference struct elements just by using an [ljass]integer[/ljass] variable.

The idea itself is good, though (aka I don't use AIDS so I honestly don't know how it's supposed to be used). Are you sure simply using :

[ljass]local random_name Struct=random_name[Unit][/ljass] doesn't work?...
 

W!†A_cRaft

Ultra Cool Member
Reaction score
28
Is not a correct syntax. It's like saying :

[ljass]return unit[/ljass]
or
[ljass]return real[/ljass].

[ljass]return this[/ljass] would be a correct syntax.

And you should use [ljass]local random_name Struct[/ljass] instead of [ljass]local integer Struct[/ljass]. I actually never tried, but I don't think you can reference struct elements just by using an [ljass]integer[/ljass] variable.

The idea itself is good, though (aka I don't use AIDS so I honestly don't know how it's supposed to be used). Are you sure simply using :

[ljass]local random_name Struct=random_name[Unit][/ljass] doesn't work?...


local random_name Struct < ----- here random name is a variable and Struct is it's name yes?
 

Laiev

Hey Listen!!
Reaction score
188
And you should use [ljass]local random_name Struct[/ljass] instead of [ljass]local integer Struct[/ljass].
i'm not creating or referring a struct itself, i'm just getting the value of that method..

I actually never tried, but I don't think you can reference struct elements just by using an [ljass]integer[/ljass] variable.
Struct = integer if you don't know

The idea itself is good, though (aka I don't use AIDS so I honestly don't know how it's supposed to be used). Are you sure simply using :

[ljass]local random_name Struct=random_name[Unit][/ljass] doesn't work?...
I don't think so
 

luorax

Invasion in Duskwood
Reaction score
67
I looked for the operator in the AIDS struct, and i found this

JASS:
static method operator[] takes unit whichUnit returns thistype
    return GetUnitId(whichUnit)
endmethod


so i think this will work:

JASS:
local &lt;struct_name&gt; testvar = &lt;struct_name&gt;[&lt;unit&gt;]

//An example:
function Test takes unit u returns Teststruct
    return Teststruct<u>
endfunction</u>


JASS:
private function ondamage_actions takes nothing returns nothing
    local unit u = GetEventDamageSource()
    local Champion ch = Champion<u>
    local real dmg = GetEventDamage()
    local unit target = GetTriggerUnit()
    set ch.coefficient = 1.45
endfunction</u>
 

Ashlebede

New Member
Reaction score
43
Struct = integer if you don't know

Yes, but can you use that integer as though it was a struct in the vJass code? Will it still compile?

[ljass]local random_name Struct=random_name[Unit][/ljass] doesn't work?...
I don't think so

Why not? I mean, except the fact that the array & struct both have the same name, which shouldn't matter once compiled but could return some syntax error.

JASS:
//! indent
    local unit u = GetEventDamageSource()
    local Champion ch = Champion


Since when can you use a unit as an array index?
 

Ashlebede

New Member
Reaction score
43
Since when is equal a custom operator to an array index?

Custom operator? Where? You don't need a custom operator to set a variable to an array member...

Plain Jass :

[ljass]local integer i = udg_intArray[10][/ljass]

Is correct syntax...
 

luorax

Invasion in Duskwood
Reaction score
67
I'm not an idiot, i know how do arrays work... but where did you saw arrays? Here's my post, read it once again:

I looked for the operator in the AIDS struct, and i found this

JASS:
static method operator[] takes unit whichUnit returns thistype
    return GetUnitId(whichUnit)
endmethod


so i think this will work:

JASS:
local &lt;struct_name&gt; testvar = &lt;struct_name&gt;[&lt;unit&gt;]

//An example:
function Test takes unit u returns Teststruct
    return Teststruct<u>
endfunction</u>


JASS:
private function ondamage_actions takes nothing returns nothing
    local unit u = GetEventDamageSource()
    local Champion ch = Champion<u>
    local real dmg = GetEventDamage()
    local unit target = GetTriggerUnit()
    set ch.coefficient = 1.45
endfunction</u>
 

Laiev

Hey Listen!!
Reaction score
188
Yes, but can you use that integer as though it was a struct in the vJass code? Will it still compile?

Yes, look at Key Timer 2 by Jesus4Lyf, search for function Add or Get, you'll see (takes integer struct) :)



Since when can you use a unit as an array index?

Since Vexorian allow it with struct and custom operator



Custom operator? Where? You don't need a custom operator to set a variable to an array member...

Plain Jass :

[ljass]local integer i = udg_intArray[10][/ljass]

Is correct syntax...

JASS:
    //! textmacro AIDS
        // This magic line makes default methods get called which do nothing
        // if the methods are otherwise undefined.
        private static delegate AIDS_DEFAULT AIDS_DELEGATE=0
        
        //-----------------------------------------------------------------------
        // Gotta know whether or not to destroy on deallocation...
        private boolean AIDS_instanciated
        
        //-----------------------------------------------------------------------
        static method operator[] takes unit whichUnit returns thistype
            return GetUnitId(whichUnit)
        endmethod
        
        method operator unit takes nothing returns unit
            // Allows structVar.unit to return the unit.
            return GetIndexUnit(this)
        endmethod
        
        //-----------------------------------------------------------------------
        method AIDS_addLock takes nothing returns nothing
            call AIDS_AddLock(this)
        endmethod
        method AIDS_removeLock takes nothing returns nothing
            call AIDS_RemoveLock(this)
        endmethod
        
        //-----------------------------------------------------------------------
        private static method AIDS_onEnter takes nothing returns boolean
            // At this point, the unit might not have been assigned an index.
            if thistype.AIDS_filter(AIDS_GetEnteringIndexUnit()) then
                // Flag it for destruction on deallocation.
                set thistype(AIDS_GetIndexOfEnteringUnit()).AIDS_instanciated=true
                // Can use inlining &quot;Assigned&quot; function now, as it must be assigned.
                call thistype(AIDS_GetIndexOfEnteringUnitAllocated()).AIDS_onCreate()
            endif
            
            return false
        endmethod
        
        private static method AIDS_onEnterAllocated takes nothing returns boolean
            // At this point, the unit must have been assigned an index.
            if thistype.AIDS_filter(AIDS_GetEnteringIndexUnit()) then
                // Flag it for destruction on deallocation. Slightly faster!
                set thistype(AIDS_GetIndexOfEnteringUnitAllocated()).AIDS_instanciated=true
                // Can use inlining &quot;Assigned&quot; function now, as it must be assigned.
                call thistype(AIDS_GetIndexOfEnteringUnitAllocated()).AIDS_onCreate()
            endif
            
            return false
        endmethod
        
        private static method AIDS_onDeallocate takes nothing returns boolean
            if thistype(AIDS_GetDecayingIndex()).AIDS_instanciated then
                call thistype(AIDS_GetDecayingIndex()).AIDS_onDestroy()
                // Unflag destruction on deallocation.
                set thistype(AIDS_GetDecayingIndex()).AIDS_instanciated=false
            endif
            
            return false
        endmethod
        
        //-----------------------------------------------------------------------
        private static method onInit takes nothing returns nothing
            call AIDS_RegisterOnEnter(Filter(function thistype.AIDS_onEnter))
            call AIDS_RegisterOnEnterAllocated(Filter(function thistype.AIDS_onEnterAllocated))
            call AIDS_RegisterOnDeallocate(Filter(function thistype.AIDS_onDeallocate))
            
            // Because I robbed you of your struct&#039;s onInit method.
            call thistype.AIDS_onInit()
        endmethod
    //! endtextmacro


read the system before anything... look at [ljass]static method operator[] takes unit whichUnit returns thistype[/ljass]
 
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