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

[vJASS] Presumably a bug

Status
Not open for further replies.

Chaosy

Tutorial Reviewer
Level 40
Joined
Jun 9, 2011
Messages
13,182
I am trying to use AutoCastSystem v1.2 but I get a very annoying bug.
JassHelper says: "ACS is not of a type that allows . syntax"
JASS:
function onInit() {
    Wat t = Wat.create();
    ACS x = ACS.register(CreateUnit(Player(0), 'Hpal', 0, 0, 0)); //it does not work with x.register either. In fact it gives the same error.
}


This is the demo used for the system.
JASS:
globals
    ACS warden
endglobals
function CastAITestWarden takes unit u returns nothing
    set warden = warden.register(u)
 
    call warden.spellTypePointTarget(function CastPointEnemy, 852238) //rain of fire (channel)
    call warden.spellTypePointTarget(function CastPointEnemy, 852525) //blink
 
    call warden.spellTypeUnitTarget(function CastChanceTargetEnemy, 852106) //ensnare
    call warden.spellTypeUnitTarget(function CastChanceTargetEnemy, 852527) //shadow strike
 
    call warden.spellTypeNoTarget(function CastChanceNoTarget, 852526) //fan of knives
 
    call warden.launch(1.0)
endfunction

I created a struct on my own and compared the two methods. They are identical.
JASS:
//mine
static method create() -> thistype {
                thistype this = thistype.allocate();
                return this;
            }

//ACS
static method register takes unit caster returns thistype
        local thistype this
        if ...
            ...
        else
            set this = allocate()
            ...
        endif
        return this
    endmethod
 
Last edited:

Chaosy

Tutorial Reviewer
Level 40
Joined
Jun 9, 2011
Messages
13,182
Kay.
JASS:
//! zinc
    library ACI requires AutoCastSystem, RandomUnit {
       
        private function UnitAlive (unit u) -> boolean {
            return !IsUnitType(u, UNIT_TYPE_DEAD) && GetUnitTypeId(u)!=0;
        }

        private function FilterAllies (unit flteredUnit) -> boolean  {
            return UnitAlive(flteredUnit) && !IsUnitEnemy(CS.caster, GetOwningPlayer(flteredUnit));
        }

        private function FilterEnemies (unit flteredUnit) -> boolean  {
            return UnitAlive(flteredUnit) && IsUnitEnemy(CS.caster, GetOwningPlayer(flteredUnit));
        }
       
       
        /*******************************************************
        *   FILTERS
        ********************************************************/
       
       
        private function CheckAlly() -> boolean {
            return FilterAllies(GetFilterUnit());
        }

        private function CheckEnemies() -> boolean {
            return FilterEnemies(GetFilterUnit());
        }

        private function TargetEnemyNonStructure() -> boolean {
            return FilterEnemies(GetFilterUnit()) && !IsUnitType(GetFilterUnit(), UNIT_TYPE_STRUCTURE);
        }

        private function TargetEnemyStructure () -> boolean {
            return FilterEnemies(GetFilterUnit()) && IsUnitType(GetFilterUnit(), UNIT_TYPE_STRUCTURE);
        }

        private function TargetEnemyFlyers() -> boolean {
            return FilterEnemies(GetFilterUnit()) && IsUnitType(GetFilterUnit(), UNIT_TYPE_FLYING);
        }
       
       
        /*******************************************************
        *   NO-TARGET
        ********************************************************/
       
       
        private function CastChanceNoTarget() -> boolean {
            boolean b = false;
            if (GetRandomInt(0, 100) < 80) {
                 CS.target = GetRandomUnitInArea(GetUnitX(CS.caster), GetUnitY(CS.caster), 500, Filter(function CheckEnemies));
                if (CS.target!=null) {
                     b = true;
                }
            }
            return b;
        }

       
        /*******************************************************
        *   TARGET UNIT
        ********************************************************/
       
       
        private function CastHealAlly() -> boolean {
            CS.target = GetRandomUnitInArea(GetUnitX(CS.caster), GetUnitY(CS.caster), 900, Filter(function CheckAlly));
            if (CS.target!=null && GetWidgetLife(CS.target) < GetUnitState(CS.target, UNIT_STATE_MAX_LIFE) && GetUnitAbilityLevel(CS.target, 'Brej')==0) {
                return true;
            }
            return false;
        }

        private function CastTargetEnemy() -> boolean {
            CS.target = GetRandomUnitInArea(GetUnitX(CS.caster), GetUnitY(CS.caster), 900, Filter(function TargetEnemyNonStructure));
            return CS.target!=null;
        }

        private function CastChanceTargetEnemy() -> boolean {
            boolean b = false;
            if (GetRandomInt(0, 100) < 70) {
                CS.target = GetRandomUnitInArea(GetUnitX(CS.caster), GetUnitY(CS.caster), 900, Filter(function TargetEnemyFlyers)); 
                if (CS.target!=null && GetUnitAbilityLevel(CS.target, 'Bena')==0) {
                     b = true;
                }        
            }  
            return b;
        }

       
        /*******************************************************
        *   TARGET POINT
        ********************************************************/
       
       
        //This is how to manipulate the spell's execution, this is a condition for the spell to take place
        //if it -> true the spell is casted
        private function CastPointEnemy() -> boolean {
            /********************************************
                Struct globals you may use, these are self explanatory
                    CS.caster
                    CS.target
                    CS.SpellTargetX
                    CS.SpellTargetY  
            *********************************************/
            CS.target = GetRandomUnitInArea(GetUnitX(CS.caster), GetUnitY(CS.caster), 900, Filter(function TargetEnemyNonStructure));
            if (CS.target!=null) {
                 CS.SpellTargetX = GetUnitX(CS.target);
                 CS.SpellTargetY = GetUnitY(CS.target);
                return true;
            }
           
            //if you do not have a target but just want to cast a spell in the XY of the map
            //you may  the CS.SpellTargetX and CS.SpellTargetY to a coordinate you like
            //and just return true, but remember that the XY MUST be in range of spell
            return false;
        }
        function ntest(unit u){
            //static method register takes unit caster returns thistype
            //ACS x = ACS.register(u);
        }
        struct Wat {
           
            method setup(unit u){
                //ACS x = x.register(u);
                /*name.spellTypeUnitTarget(function CastHealAlly, holybolt);
                name.spellTypeNoTarget(function CastHealAlly, divineshield);
                name.spellTypeNoTarget(function CastHealAlly, resurrection);
                name.launch(1.0);*/
            }
           
            static method create() -> thistype {
                thistype this = thistype.allocate();
                return this;
            }
        }
       
        function onInit() {
            //Wat t = Wat.create();
            //ACS x = ACS.register(CreateUnit(Player(0), 'Hpal', 0, 0, 0));
            ACS x = ACS.register(CreateUnit(Player(0), 'Hpal', 0, 0, 0));

            /*paladin.spellTypeUnitTarget(function CastHealAlly, holybolt);
            paladin.spellTypeNoTarget(function CastHealAlly, divineshield);
            paladin.spellTypeNoTarget(function CastHealAlly, resurrection);
            paladin.launch(1.0);*/
           
            /*
                method spellTypeUnitTarget takes code func, integer spellOrderID returns nothing
                method spellTypePointTarget takes code func, integer spellOrderID returns nothing
                method spellTypeNoTarget takes code func, integer spellOrderID returns nothing 
            */
        }
    }
//! endzinc
 
"public" is good, because you can use generic names like "Add" or so as function names inside your library or scope.

So for not conflicting with others, which also maybe wanna work with short and good names, you can just make declare it as "public", but then from outside they need the library name to access it.

If they are neither private nor public, you can simply call them without any extra, if you require the library, but then the name must be very unique.
 
Last edited:
Level 7
Joined
Oct 19, 2015
Messages
286
The public prefix works differently in vJass and zinc. In vJass, library members are public by default, so explicitly marking them as public means JassHelper will add a "LIBRARYNAME_" prefix to them. In zinc, library members are private by default, so you need to mark them as public in order to use them outside the library and when you do that, no prefix gets added to their name.
 
Status
Not open for further replies.
Top