When the 30th cast comes, bug will spawn.

Nherwyziant

Be better than you were yesterday :D
Reaction score
96
Hello, I was making a spell, but when the 30th cast of the spell, a bug is spawning. I dunno why. I was not thinking to ask, cuz I was making a spell pack for waaaks RoS, but since I can't fix this, the bug has forced me to ask.

//Note that this spell is not yet finished so don't say anything, like "hey, lol why no damage?".

//Requires: TimerUtils(RedFlavor, by Vexorian), GTrigger(J4L)

JASS:
scope LightningTentacle
    private struct s
        private static constant real    DISTANCE  = 100.   //Distance moved per period.
        private static constant real    PERIODIC  = .05    //Period.
        private static constant real    WORMS     = 25     //Number of worms.
        private static constant integer MAX       = 10     //Max number of worm segments.
        private static constant integer MOVES     = 50     //Number of moves.
        private static constant integer RAWCODE   = 'A002' //The rawcode of the spell.
        
        private static constant real REDCOLOR     = 1.     //Lightning color red
        private static constant real GREENCOLOR   = 1.     //Lightning color green
        private static constant real BLUECOLOR    = 1.     //Lightning color blue
        private static constant real ALPHA        = .5     //Lightning Alpha

        private static constant string  LIGHTNING = "DRAL" //The Lightning Effect.
        private static constant string  EFFECT1   = ""
        private static constant string  EFFECT2   = ""

        real array x[11]
        real array y[11]
        lightning array l[10]

        //DO NOT TOUCH THIS PART===================================================================================

        unit u
        unit c
        real a
        timer t
        effect e
        integer v
        integer d

        method Destroy takes nothing returns nothing
            call ReleaseTimer(.t)

            set .u = null
            set .c = null
            set .t = null
            set .v = 0
            loop
                set .v = .v+1
                set .l[.v] = null
                exitwhen .v == MAX
            endloop
        endmethod

        static method create takes unit u returns s
            local s this = s.allocate()
            set .t = NewTimer()
            set .u = u
            return this
        endmethod

        static method Remove takes nothing returns nothing
            local s this = GetTimerData(GetExpiredTimer())

            set .v = .v-1
            call DestroyLightning(.l[.v])

            if .v == 1 then
                call .Destroy()
            endif
        endmethod

        method Fader takes nothing returns nothing
            call ReleaseTimer(.t)

            set .v = MAX+1
            set .t = NewTimer()
            call DestroyEffect(.e)
            call SetTimerData(.t,this)
            call TimerStart(.t,PERIODIC,true,function s.Remove)
        endmethod

        static method Mover takes nothing returns nothing
            local s this = GetTimerData(GetExpiredTimer())

            set .d = .d+1
            set .v = MAX+1

            loop
                set .v = .v-1
                if .x[.v] == .x[1] and .y[.v] == .y[1] then
                    set .x[1] = .x[1]+DISTANCE*Cos(a+GetRandomInt(-90,90)*bj_DEGTORAD)
                    set .y[1] = .y[1]+DISTANCE*Sin(a+GetRandomInt(-90,90)*bj_DEGTORAD)
                else
                    set .x[.v] = .x[.v-1]
                    set .y[.v] = .y[.v-1]
                endif
                exitwhen .v == 1
            endloop

            set .v = 0

            loop
                set .v = .v+1
                call MoveLightning(.l[.v],true,.x[.v+1],.y[.v+1],.x[.v],.y[.v])
                if .l[.v] == .l[1] then
                    if .e != null then
                        call DestroyEffect(.e)
                    endif
                    set .e = AddSpecialEffect(EFFECT1,.x[.v],.y[.v])
                endif
                exitwhen .v == MAX-1
            endloop

            if .d >= MOVES then
                call .Fader()
            endif
        endmethod

        static method Act takes nothing returns nothing
            local unit u = GetSpellAbilityUnit()
            local s this = s.create(u)

            set .x[1] = GetUnitX(.u)
            set .y[1] = GetUnitY(.u)
            set .a = Atan2(.y[1]+DISTANCE*Sin(GetRandomInt(0,360)*bj_DEGTORAD)-.y[1],(.x[1]+DISTANCE*Cos(GetRandomInt(0,360)*bj_DEGTORAD))-.x[1])
            set .v = MAX+1

            loop
                set .v = .v-1
                if .x[.v] == .x[1] and .y[.v] == .y[1] then
                    set .x[1] = .x[1]+DISTANCE*Cos(a)
                    set .y[1] = .y[1]+DISTANCE*Sin(a)
                else
                    set .x[.v] = GetUnitX(.u)
                    set .y[.v] = GetUnitY(.u)
                endif

                exitwhen .v == 1
            endloop
            
            set .v = 0

            loop
                set .v = .v+1

                set .l[.v] = AddLightning(LIGHTNING,true,.x[.v+1],.y[.v+1],.x[.v],.y[.v])
                call SetLightningColor(.l[.v],REDCOLOR,GREENCOLOR,BLUECOLOR,ALPHA)
                exitwhen .v == MAX-1
            endloop

            call SetTimerData(.t,this)
            call TimerStart(.t,PERIODIC,true,function s.Mover)
        endmethod

        static method Action takes nothing returns nothing
            local integer i = 0
            loop
                set i = i+1
                call s.Act()
                exitwhen i==WORMS
            endloop
        endmethod

        private static method onInit takes nothing returns nothing
            local trigger g = CreateTrigger()
            call GT_RegisterStartsEffectEvent(g,RAWCODE)
            call TriggerAddAction(g,function s.Action)
        endmethod
    endstruct
endscope


MADE in china, woops I mean in 1.24b version. Help plz.

Here's the spelll
 

waaaks!

Zinctified
Reaction score
255
ok, I tried the spell, also tried tweaking the spell, I noticed that when WORMS count is too much, it will bug in the 30th cast, I tried lowering the WORMS value from 25 to 15, I don't know when will the bug will occur again, because no bug appeared in the 30th cast.

You have lots of calculations and loops, which makes the spell slow in terms of time, which will cause lag.
So I simply remade your code to my version. Please note that this version still causes lag when WORMS is set to a high value (ex. 25), anyways, 10 for WORMS is enough.

here's my version
JASS:
//! zinc
library LightningTentacle requires TimerUtils{
    constant integer SPELL = 'A002';
    constant integer MOVES = 15; //amount of movement per segment
    constant integer WORMS = 10; //amount of tentacles
    constant integer ANGLE = 60; //angle of frizziness, lower = straighter
    constant string FORM = "DRAL"; //lightning form
    constant real TICK = 0.05; //tick per movement change
    constant real DIST = 100.0; //lenght of each segment
    constant string sfx = "Abilities\\Spells\\Human\\ManaFlare\\ManaFlareBoltImpact.mdl"; //effect spawned on each cast
    
    struct dest{
        lightning l;
        static method create(lightning lg)->dest{
            dest d = dest.allocate();
            timer t = NewTimer();
            d.l = lg;
            SetTimerData(t,d);
            TimerStart(t,0.4,false,function(){
                timer t = GetExpiredTimer();
                dest d = GetTimerData(t);
                DestroyLightning(d.l);
                ReleaseTimer(t);
                d.destroy();
                t = null;
                d.l = null;
            });
            t = null;
            return d;
        }
    }
    
    struct tentacle{
        unit c;
        real nx,ny,pa;
        lightning light;
        integer movesCtr,ctr;
        
        static method create(unit owner)->tentacle{
            tentacle d = tentacle.allocate();
            real a,x=GetUnitX(owner),y=GetUnitY(owner),px,py;
            timer t = NewTimer();
            d.c = owner;
            a = Atan2(y+DIST*Sin(GetRandomInt(0,360)*bj_DEGTORAD)-y,(x+DIST*Cos(GetRandomInt(0,360)*bj_DEGTORAD))-x);
            px = x + DIST * Cos(a);
            py = y + DIST * Sin(a);
            d.pa = a;
            d.nx = px;
            d.ny = py;
            d.light = AddLightning(FORM,true,x,y,px,py);
            SetLightningColor(d.light,1,1,1,0.5);
            d.movesCtr = 0;
            d.ctr = 0;
            SetTimerData(t,d);
            TimerStart(t,TICK,true,function(){
                timer t = GetExpiredTimer();
                timer ts;
                tentacle d = GetTimerData(t);
                real x = d.nx, y = d.ny, a;
                dest ds;
                if(d.movesCtr >= MOVES){
                    d.movesCtr = 0;
                    ReleaseTimer(t);
                    d.destroy();
                }else{
                    a = d.pa + (bj_DEGTORAD * GetRandomInt(-ANGLE,ANGLE));
                    d.nx = x + DIST * Cos(a);
                    d.ny = y + DIST * Sin(a);
                    ds.create(d.light);
                    d.light = AddLightning(FORM,true,x,y,d.nx,d.ny);
                    SetLightningColor(d.light,1,1,1,0.5);
                }
                d.movesCtr += 1;
                t = null;
                ts = null;
            });
            t = null;
            return d;
        }
        
        method onDestroy(){
            dest ds = dest.create(light);
            light = null;
        }
    }
    
    struct data{
        unit c;
        integer ctr;
    }
    
    function act(){
        unit c = GetTriggerUnit();
        integer n;
        timer t = NewTimer();
        data d = data.create();
        d.c = c;
        d.ctr = 0;
        SetTimerData(t,d);
        TimerStart(t,0.035,true,function(){
            timer t = GetExpiredTimer();
            data d = GetTimerData(t);
            tentacle te;
            if(d.ctr >= WORMS){
                d.ctr = 0;
                ReleaseTimer(t);
                d.destroy();
            }else{
                te = tentacle.create(d.c);
            }
            d.ctr += 1;
            t = null;
        });
        DestroyEffect(AddSpecialEffect(sfx,GetUnitX(c),GetUnitY(c)));
        c = null;
        t = null;
    }
    
    function abilityCheck()->boolean{
        return GetSpellAbilityId() == SPELL;
    }
    
    function onInit(){
        trigger t = CreateTrigger();
        TriggerRegisterAnyUnitEventBJ(t,EVENT_PLAYER_UNIT_SPELL_EFFECT);
        TriggerAddCondition(t,Condition(function abilityCheck));
        TriggerAddAction(t,function act);
    }
}
//! endzinc


also please update your TimerUtils
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top