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.
  • Ghan Ghan:
    Howdy
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • 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 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