Lightning Bolts

This little two-function script creates a lightning effect from two points (given as x/y values) and fades it out over the next second. It uses a trigger and polledwait to fade. As far as I know all leaks are cleaned.

JASS:
function Bolt_Child takes nothing returns nothing
    local lightning l=bj_lastCreatedLightning
    local real a=1
    loop
        call PolledWait(0.25)
        set alpha=a-0.25
        exitwhen a<=0
        call SetLightningColor(l,1,1,1,a)
    endloop
    call DestroyLightning(l)
    set l=null
endfunction
function AddBolt takes string style,real x1,real y1,real x2,real y2 returns nothing
    local lightning l=AddLightning(style,true,x1,y1,x2,y2)
    local trigger t=CreateTrigger()
    set bj_lastCreatedLightning=l
    call TriggerAddAction(t,function Bolt_Child)
    call TriggerExecute(t)
    call DestroyTrigger(t)
    //Call RemoveLightning(l) [This line accually causes WC3 to crash, or it did for me]
    set t=null
    set l=null
endfunction
 
yea... this has a lot of problems... so many I'd almost rewrite it..

first you need to learn vjass >.>

from the fact you used PolledWait/bj_lastCreatedLightning, I'm guessing this is one of the first things you've ever scripted = )

I mean, really, I'd delete the whole script and start over.

For me to give feedback on this would be to rewrite it for you, which would probably hurt you as a coder ; ), so imma be shush shush.
 
To start off
JASS:
struct Hello extends array
    private static integer instanceCount = 0
    private static integer array recycle
    private static integer recycleCount = 0

    public static method create takes nothing returns thistype
        local thistype this
        if (recycleCount != 0) then
            set recycleCount = recycleCount - 1
            set this = recycle[recycleCount]
        else
            set instanceCount = instanceCount + 1
            set this = instanceCount
        endif
        return this
    endmethod

    public method destroy takes nothing returns nothing
        set recycle[recycleCount] = this
        set recycleCount = recycleCount + 1
    endmethod
endstruct

First understand the above code so that you can even begin to attempt to make something : ).

At your current level, you really shouldn't be coding resources

*votes for rejection*

Come back after you've learned what you need to know to make this stuff, kk : ).
 
Last edited:
Nestharus, you don't need vjass to make something or we'd have nothing to use since vjass came after WC3.

Axarion, The trigger is so the loop can run and use PolledWait with out making the trigger that called the function to also wait. That's an interesting thing with triggers and waits in WC3. Secondly; the use of a bj global was so that you can copy this code without making a global, just less for someone using this to do.
 
Nestharus, you don't need vjass to make something or we'd have nothing to use since vjass came after WC3.

Axarion, The trigger is so the loop can run and use PolledWait with out making the trigger that called the function to also wait. That's an interesting thing with triggers and waits in WC3. Secondly; the use of a bj global was so that you can copy this code without making a global, just less for someone using this to do.

I rest my case.

Now stop making silly arguments and go study...
 
Last edited:
Nestharus, you don't need vjass to make something or we'd have nothing to use since vjass came after WC3.

Axarion, The trigger is so the loop can run and use PolledWait with out making the trigger that called the function to also wait. That's an interesting thing with triggers and waits in WC3. Secondly; the use of a bj global was so that you can copy this code without making a global, just less for someone using this to do.

I think he means make a global using this:

JASS:
globals
//insert global here
endglobals

I wont ask you to use vjass but I think you should find a workaround to remove that polledwait and avoid creating a trigger everytime... (you can try to learn indexing...)
 
Top