• 🏆 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!

[Solved] Struct member returns 0

Status
Not open for further replies.

Chaosy

Tutorial Reviewer
Level 40
Joined
Jun 9, 2011
Messages
13,183
Another problem came up however.

JASS:
static method  create(integer upgrade, integer g, integer l, integer num, real val) -> thistype {
                thistype this = thistype.allocate();
                tech = upgrade;
                gold = g;
                lumber = l;
                id = num;
                BJDebugMsg(I2S(id)); //writes out a number properly
                value = val;
                return this;
            }
JASS:
BJDebugMsg(I2S(this.id)); //writes 0 and yes, I tried without this. as well
if(u == null) {
    break;
} else if(GetUnitTypeId(u) == id) { //this never works
    break;
}

id is private so it cannot be changed from another trigger, and it is not used anywhere else within the class.

JASS:
//! zinc
    library ResearchUtils
    {
        function filter() -> boolean{
            return UnitAlive(GetFilterUnit());
        }
      
        public struct info {
            public unit u;
            public boolean check;
            public string reason;
          
            static method create(boolean tcheck) -> thistype {
                thistype this = thistype.allocate();
                check = tcheck;
                reason = "Default";
                return this;
            }
        }
      
        public struct Research {
            integer tech;
            integer gold;
            integer lumber;
            private integer id;
            real value;
            static method  create(integer upgrade, integer g, integer l, integer num, real val) -> thistype {
                thistype this = thistype.allocate();
                tech = upgrade;
                gold = g;
                lumber = l;
                id = num;
                BJDebugMsg(I2S(id));
                value = val;
                return this;
            }
          
            method isUpgraded(player p) -> boolean {
                return GetPlayerTechCount(p, tech, true) > 0;
            }
          
            method canAfford(player p) -> boolean {
                return GetPlayerState(p, PLAYER_STATE_RESOURCE_GOLD) >= gold && GetPlayerState(p, PLAYER_STATE_RESOURCE_LUMBER) >= lumber;
            }
          
            method filter() -> boolean{
                return UnitAlive(GetFilterUnit());
            }
          
            method canUpgrade(player p) -> info {
                unit u;
                group g;
                info i;
                i = info.create(true);
              
                if(!isUpgraded(p) && canAfford(p)) {
                    g = GetUnitsOfPlayerMatching(p, Condition(function filter));
                    while(true) {
                        u = FirstOfGroup(g);
                        GroupRemoveUnit(g, u);
                        //BJDebugMsg(I2S(GetUnitTypeId(u)));
                        BJDebugMsg(I2S(this.id));
                        if(u == null) {
                            break;
                        } else if(GetUnitTypeId(u) == id) {
                            break;
                        }
                    }
                    if(u == null) {
                        i.reason = "No unit to do the upgrade";
                        i.check = false;
                        return i;
                    } else {
                        i.u = u;
                    }
                }
              
                if(isUpgraded(p)) {
                    i.reason = "Is already upgraded";
                    i.check = false;
                }
              
                if(!canAfford(p)) {
                    i.reason = "Cannot afford";
                    i.check = false;
                }
                return i;
            }
        }  
    }
//! endzinc
 
Last edited:
Status
Not open for further replies.
Top