• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

Structs...

Status
Not open for further replies.
Level 6
Joined
Jan 15, 2005
Messages
188
I've just started into JASS, and I have a question:

What are structs? I've got something like this:

Code:
struct HeroStruct
  unit this
  integer unitType
  player owner
  //Item Stuff
  boolean isLookingAtEquipment
  unit isNotLookingAtEquipment
  item slot0
  integer id0
  item slot1
  integer id1
  item slot2
  integer id2
  item slot3
  integer id3
  item slot4
  item slot5
  item norm0
  item norm1
  item norm2
  item norm3
  item norm4
  item norm5
  //Base item stats
  integer itemDamage
  integer itemArmor
  real itemHealthRegen
  integer itemHealth
  real itemManaRegen
  integer itemMana
  integer itemSpeed
  //Item bonus
  integer itemSta
  integer itemPow
  integer itemEss
endstruct

globals
  constant integer maxLevel = 62
endglobals

//===========================================================================
//Set and Get
function SetHeroStruct takes unit u, HeroStruct hs returns nothing
    set hs.this = u
    call AttachInt( u, "structIndex", hs )
endfunction
function InitHeroStruct takes unit u returns nothing
  local HeroStruct hs = HeroStruct( udg_IndexHeroStruct )
    loop
        if( hs.unitType == 0 ) then
            set hs.unitType = GetUnitTypeId(u)
            call SetHeroStruct( u, hs )
            exitwhen true
        else
            set udg_IndexHeroStruct = udg_IndexHeroStruct + 1
            if( udg_IndexHeroStruct > 8190 ) then
                set udg_IndexHeroStruct = 1
            endif
            set hs = HeroStruct( udg_IndexHeroStruct )
        endif
    endloop
endfunction
function GetHeroStruct takes unit u returns HeroStruct
  return HeroStruct( GetAttachedInt( u, "structIndex" ) )
endfunction
function DestroyHeroStruct takes unit u returns nothing
  local HeroStruct s = GetHeroStruct( u )
    set s.unitType = 0
endfunction

However, I don't understand it properly, as I don't know about Structs. Could someone explain structs to me, and if you have the time read over what the code is and explain to me what it does in nooby terms?
 
Level 19
Joined
Aug 24, 2007
Messages
2,888
Group of arrayed variables for struct index
liek
struct A
unit u
endstruct

somefunction
local A s = A.create()
set s.u = GetTriggeringUnit()

create() is a native struct method for generating a non-used index for specified struct type
A is struct type
s is index (integer, yea you can store with SetHandleInt)
u is a member of A type

Dont think you will understand (I didnt at start)
But it will make sense later
 
Status
Not open for further replies.
Top