- 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:
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?
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?