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
 
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.
  • jonas jonas:
    we already have a wealth tax on our house, it's called a property tax. I'm talking about extending that to other income-generating assets like private equity, bonds and stocks.
  • jonas jonas:
    I agree that the effect of that would be to depress asset prices, but I think that's a good thing. Makes it easier for hard working young people to grow their retirement income
    +1
  • seph ir oth seph ir oth:
    Potential problem for a wealth tax for the US would be the ultra rich just offshoring assets in another country without a wealth tax. Those that would eat the wealth tax on, say, stocks, would be the middle class that puts money slowly into the market via the likes of funds.
  • seph ir oth seph ir oth:
    happy US election day btw!
  • Varine Varine:
    Oh election day
  • The Helper The Helper:
    Election day has come and gone now it is time to sit back and watch the liberals melt down. At least it should be peaceful around my house as my roommate is as trumper as you can get.
    +2
  • jonas jonas:
    curious what the next years will bring
  • jonas jonas:
    I think at least it's good that Trump has a solid lead in the popular vote
  • The Helper The Helper:
    It will depend on what happens with the house race. The Conservatives have the president and the senate, I believe the house majority is up too. With the conservatives stacked in the supreme court now would be the time they could really do something
  • The Helper The Helper:
    I just hope its not anything stupid like banning abortion nationally or doubling down on the border wall
  • jonas jonas:
    Well, the border wall at least doesn't really harm anyone. It's true that Trump only managed to add about new 80 miles to the 650 miles built by Obama and Bush, and that it didn't do much to reduce the number of illegal immigrants, but still, it's construction jobs and doesn't hurt anyone.
  • jonas jonas:
    One can of course argue whether the money is better spent somewhere else, like reducing taxes
  • jonas jonas:
    I'm more curious what Trump will do in foreign policy and how that will affect the US/European coalition, and the balance of power in europe and ME
  • The Helper The Helper:
    I am more of a fan of fixing the broken immigration laws and looking at protecting border with drone tech or some other way I mean I just think its ridiculous to build a great wall of mexico
    +2
  • Ghan Ghan:
    Trump's foreign policy was fantastic in his last term. More of that, please. Finish the Abraham Accords. Get Saudi in. Build the coalition against Iran.
    +1
  • Lord of Bourbon Lord of Bourbon:
    Just a friendly reminder to watch your sodium intake, too much can result in harmful effects
    +1
  • The Helper The Helper:
    Thank you for the health tip Lord of Bourbon!
  • The Helper The Helper:
    I hate to even say anything because it always seems to start again after I do it but the bots have been gone for like 3 days now. Looks like the AI scraping bots are onto better pastures, are done sucking us dry, or are taking a vactation :)
  • Lord of Bourbon Lord of Bourbon:
    The bots are probably mining salt else where right now, given that the mines have reopened.
  • The Helper The Helper:
    Got a user online that has like 10 different accounts dating back like 7 years and he is cycling through them. I have too much time on my hands LOL
    +1
  • The Helper The Helper:
    like half of them are banned with no notes why
  • The Helper The Helper:
    I made this the other day it was Awesome! Chicken Pot Pie Pasta - https://www.thehelper.net/threads/chicken-chicken-pot-pie-pasta.197065/
  • The Helper The Helper:
    New Thanksgiving Holiday Appetizer recipe Turking Stuffing Balls - https://www.thehelper.net/threads/appetizer-turkey-stuffing-balls.197078/

      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