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?
 
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.
 
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.
 
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
 
[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?...
 
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?
 
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
 
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>
 
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?
 
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...
 
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>
 
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.
  • V-SNES V-SNES:
    Happy Friday!
    +1
  • The Helper The Helper:
    News portal has been retired. Main page of site goes to Headline News forum now
  • The Helper The Helper:
    I am working on getting access to the old news portal under a different URL for those that would rather use that for news before we get a different news view.
  • Ghan Ghan:
    Easily done
    +1
  • The Helper The Helper:
    https://www.thehelper.net/pages/news/ is a link to the old news portal - i will integrate it into the interface somewhere when i figure it out
  • Ghan Ghan:
    Need to try something
  • Ghan Ghan:
    Hopefully this won't cause problems.
  • Ghan Ghan:
    Hmm
  • Ghan Ghan:
    I have converted the Headline News forum to an Article type forum. It will now show the top 20 threads with more detail of each thread.
  • Ghan Ghan:
    See how we like that.
  • The Helper The Helper:
    I do not see a way to go past the 1st page of posts on the forum though
  • The Helper The Helper:
    It is OK though for the main page to open up on the forum in the view it was before. As long as the portal has its own URL so it can be viewed that way I do want to try it as a regular forum view for a while
  • Ghan Ghan:
    Yeah I'm not sure what the deal is with the pagination.
  • Ghan Ghan:
    It SHOULD be there so I think it might just be an artifact of having an older style.
  • Ghan Ghan:
    I switched it to a "Standard" article forum. This will show the thread list like normal, but the threads themselves will have the first post set up above the rest of the "comments"
  • The Helper The Helper:
    I don't really get that article forum but I think it is because I have never really seen it used on a multi post thread
  • Ghan Ghan:
    RpNation makes more use of it right now as an example: https://www.rpnation.com/news/
  • The Helper The Helper:
  • The Helper The Helper:
    What do you think Tom?
  • tom_mai78101 tom_mai78101:
    I will have to get used to this.
  • tom_mai78101 tom_mai78101:
    The latest news feed looks good

      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