• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

Struct madness

Status
Not open for further replies.
Level 3
Joined
Jan 15, 2010
Messages
47
Hello all,

I am working on a custom hero stat and inventory system and I am not sure if there is syntax for what I am trying to do or not.

My structs are all below and initialized properly, I can set this manually, and check them in-game and they are correct. My issue is that I don't know how to change one structs data inside another struct from another struct. I will post my structs below, as that sentence probably won't be enough information :)

JASS:
struct itemSlot

    boolean status      // true if slot is open
    integer itemCode    // id of item
    string  name        // name of item
    integer weight      // weight of item
    
    static method create takes nothing returns thistype
        local thistype thisSlot = thistype.allocate()
        return thisSlot
    endmethod
    
    //is run when an item is equipped
    //needs to change hData item stats positively
    method equip takes integer itemID returns nothing
        set this.status = true
        set this.itemCode = itemID
        set this.name = getItemNameAll(itemID)
        set this.weight = getItemWeightAll(itemID)
        set hData[pN].Armor.Items = hData[pN].Armor.Items + 5
    endmethod
    
    //is run when an item is removed
    //needs to change hData item stats negatively
    method empty takes nothing returns nothing
        set this.status = false
        set this.itemCode = -1
        set this.name = ""
        set this.weight = 0
    endmethod
    
endstruct

JASS:
struct heroStat

    real Base       //base stat value
    real Items      //stat value bonus from items
    real Buffs      //stat value bonus from buffs
    
    static method create takes nothing returns thistype
        local thistype thisStat = thistype.allocate()
        return thisStat
    endmethod
    
    method total takes nothing returns real
        return (this.Base + this.Items + this.Buffs)
    endmethod
    
    method clear takes nothing returns nothing
        set this.Base = 0
        set this.Items = 0
    endmethod
    
endstruct

And the last (main) struct, that uses the previous two:

JASS:
struct heroData
    //hero stats
    unit        Hero = null
    boolean     HasHero = false
    string      Class = "none"
    string      Role = "none"
    string      Zone = "none"
    
    integer     WeightAllowance
    integer     WeightHeld 
    real        DetrimentalFactor
    
    integer     Experience
    
    //hero stat structs
    //! textmacro statDeclare takes INSTANCE
    heroStat $INSTANCE$
    real $INSTANCE$Current
    //! endtextmacro
    //! runtextmacro statDeclare("Armor")
    //! runtextmacro statDeclare("Life")
    //! runtextmacro statDeclare("Mana")
    //! runtextmacro statDeclare("AttackSpeed")
    //! runtextmacro statDeclare("MovementSpeed")
    //! runtextmacro statDeclare("PhysicalDamageModifier")
    //! runtextmacro statDeclare("PhysicalCritBonus")
    //! runtextmacro statDeclare("PhysicalCritChance")
    //! runtextmacro statDeclare("MeleeStunChance")
    //! runtextmacro statDeclare("SpellDamageModifier")
    //! runtextmacro statDeclare("SpellCritBonus")
    //! runtextmacro statDeclare("SpellCritChance")
    //! runtextmacro statDeclare("HealModifier")
    //! runtextmacro statDeclare("HealCritBonus")
    //! runtextmacro statDeclare("HealCritChance")
    //! runtextmacro statDeclare("BlockChance")
    //! runtextmacro statDeclare("ParryChance")
    //! runtextmacro statDeclare("DodgeChance")
    
    //hero items
    //! textmacro slotDeclare takes INSTANCE
    itemSlot $INSTANCE$Slot
    //! endtextmacro
    //! runtextmacro slotDeclare("Mainhand")
    //! runtextmacro slotDeclare("Offhand")
    //! runtextmacro slotDeclare("Head")
    //! runtextmacro slotDeclare("Chest")
    //! runtextmacro slotDeclare("Legs")
    //! runtextmacro slotDeclare("Feet")
    //! runtextmacro slotDeclare("Hands")
    //! runtextmacro slotDeclare("Neck")
    //! runtextmacro slotDeclare("FingerOne")
    //! runtextmacro slotDeclare("FingerTwo")
    
    static method create takes nothing returns thistype
        local thistype this = thistype.allocate()
        return this
    endmethod
    
endstruct

I am confused about how I could use the equip function in the itemSlot struct to change values in the heroStat struct. I have an array of heroData structs, hData.

The normal syntax to set a heroStat from outside would be:

set hData[pN].DodgeChance.Base = 30

With pN being player number. So I guess I am not sure how to do it from inside the itemSlot struct, as i figured it wouldnt require the player number... liek some sort of inverse "this"... or like a set parentStruct.DodgeChance.Base = 30 sort of thing.

Just trying to learn more about structs and I guess, if I have to, I can do a fucntion outside of the structs that uses player number, but i wanted to know if this were possible. Thanks :)
 
Status
Not open for further replies.
Top