• 🏆 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] Lightning Trigger

Status
Not open for further replies.
Level 12
Joined
Feb 11, 2008
Messages
809
Can someone tell me what would cause this code to crash and then anything that occurs after this does not run;

JASS:
// Reset Lightning
set Index[2] = 0
call DestroyLightning( TempLightning )
set Line[12] = ( "Lightning Effects : " + ( ( "(" + ( "0" + ") " ) ) + "None" ) )
call Board.setText(12,0,Line[12])
// --------------------------------------------

I have declared the global variable like this;

JASS:
globals
      lightning TempLightning
endglobals

And heres an example of me using the lightning in my system;

JASS:
            call DestroyLightning( TempLightning )
            if Index[2] != MinIndex[2] then
                set TempLightning = AddLightningEx(LightningChoice[Index[2]], true, 128.500, -12.000, 400, 128.500, -516.00, 400)
            endif
            set Line[12] = ( "Lightning Effects : " + ( ( "(" + ( I2S(Index[2]) + ") " ) ) + LightningName[Index[2]] ) )

So any ideas guys?

EDIT*

Forgot to tell you all the global is declared way before the trigger is run and once i delete this line of code the triggers work perfect but the lightning doesnt get destroyed;

JASS:
call DestroyLightning( TempLightning )

This trigger was functioning perfectly fine as a udg_TempLightning but once i changed it to a regular vJASS global without the udg_ it started failing.
 
Last edited:
Level 18
Joined
Nov 21, 2012
Messages
835
This trigger was functioning perfectly fine as a udg_TempLightning but once i changed it to a regular vJASS global without the udg_ it started failing.
if so, inspect your code for accidentally left udg_tempLightning somewhere. From what you show it looks fine, I guess LightningChoice[Index[2]] is a proper string cause you said lightning is visible, maybe show more code to find a cause
 
Level 12
Joined
Feb 11, 2008
Messages
809
if so, inspect your code for accidentally left udg_tempLightning somewhere. From what you show it looks fine, I guess LightningChoice[Index[2]] is a proper string cause you said lightning is visible, maybe show more code to find a cause

thanks for the response it is fully functioning as in displaying and changing indexs but like i said the "call DestroyLightning" breaks it.

im checking over the coding rn just to make sure but i had checked over it pretty thoroughly.

EDIT*

heres a script from my system so kind of a sneak peak for new update also lol but it does same thing here everything works perfectly until that line is inserted.

JASS:
scope ControlPanel initializer Init

    private function ControlPanelActions takes nothing returns nothing
  
        // Creating local variables
        local unit u = GetTriggerUnit()
        local integer uid = GetUnitTypeId(u)
        local integer aid = GetSpellAbilityId()
        // --------------------------------------------

        // Why Begins Casting an Ability? So that you could browse between animations a lot faster.
        call IssueImmediateOrder( u, "stop" )
        // Whats with the Stop? to prevent the Control Panel from casting anything.
        if aid == 'A004' then
            set CamMode = ( CamMode + 1 )
            if CamMode > 2 then
                set CamMode = 0
            endif
            set Line[1] = ( "Camera Mode : " + CameraModeName[CamMode] )
            call Board.setText(1,0,Line[1])
        elseif aid == 'A001' or aid == 'A000' then
            if uid == 'H002' or uid == 'H003' then
                if aid == 'A001' then
                    set Index[6] = ( Index[6] + 1 )
                else
                    set Index[6] = ( Index[6] - 1 )
                endif
                if Index[6] > MaxIndex[6] then
                    set Index[6] = MinIndex[6]
                elseif Index[6] < MinIndex[6] then
                    set Index[6] = MaxIndex[6]
                endif
                set Line[8] = ( "Unit Animations : " + ( ( "(" + ( I2S(Index[6]) + ") " ) ) + AnimationName[Index[6]] ) )
                call SetUnitAnimationByIndex(Actor[0], Index[6])
                call Board.setText(8,0,Line[8])
            else
                if aid == 'A001' then
                    set Index[7] = ( Index[7] + 1 )
                else
                    set Index[7] = ( Index[7] - 1 )
                endif
                if Index[7] > MaxIndex[7] then
                    set Index[7] = MinIndex[7]
                elseif Index[7] < MinIndex[7] then
                    set Index[7] = MaxIndex[7]
                endif
                set Line[8] = ( "Unit Animations : " + ( ( "(" + ( I2S(Index[7]) + ") " ) ) + AnimationNameA[Index[7]] ) )
                call SetUnitAnimationByIndex(Actor[1], Index[7])
                call Board.setText(8,0,Line[8])
            endif
        elseif aid == 'A006' or aid == 'A007' then
            if aid == 'A006' then
                set Index[5] = ( Index[5] + 1 )
            else
                set Index[5] = ( Index[5] - 1 )
            endif
            if Index[5] > MaxIndex[5] then
                set Index[5] = MinIndex[5]
            elseif Index[5] < MinIndex[5] then
                set Index[5] = MaxIndex[5]
            endif
            call RemoveWeatherEffect( bj_lastCreatedWeatherEffect )
            if Index[5] != MinIndex[5] then
                set bj_lastCreatedWeatherEffect = AddWeatherEffect(gg_rct_Map_Area, WeatherChoice[Index[5]])
                call EnableWeatherEffect( bj_lastCreatedWeatherEffect, true )
            endif
            set Line[9] = ( "Weather Effects : " + ( ( "(" + ( I2S(Index[5]) + ") " ) ) + WeatherName[Index[5]] ) )
            call Board.setText(9,0,Line[9])
        elseif aid == 'A00B' or aid == 'A00A' then
            if aid == 'A00B' then
                set Index[4] = ( Index[4] + 1 )
            else
                set Index[4] = ( Index[4] - 1 )
            endif
            if Index[4] > MaxIndex[4] then
                set Index[4] = MinIndex[4]
            elseif Index[4] < MinIndex[4] then
                set Index[4] = MaxIndex[4]
            endif
            if Index[4] != MinIndex[4] then
                call SetSkyModel(SkyChoice[Index[4]])
            else
                call SetSkyModel( null )
            endif
            set Line[10] = ( "Sky Models : " + ( ( "(" + ( I2S(Index[4]) + ") " ) ) + SkyName[Index[4]] ) )
            call Board.setText(10,0,Line[10])
        elseif aid == 'A00E' or aid == 'A00F' then
            if aid == 'A00E' then
                set Index[3] = ( Index[3] + 1 )
            else
                set Index[3] = ( Index[3] - 1 )
            endif
            if Index[3] > MaxIndex[3] then
                set Index[3] = MinIndex[3]
            elseif Index[3] < MinIndex[3] then
                set Index[3] = MaxIndex[3]
            endif
            if (bj_cineFadeContinueTimer != null) then
                call DestroyTimer(bj_cineFadeContinueTimer)
            elseif (bj_cineFadeFinishTimer != null) then
                call DestroyTimer(bj_cineFadeFinishTimer)
            endif
            set bj_cineFadeFinishTimer = null
            call DisplayCineFilter(false)
            if Index[3] != MinIndex[3] then
                call RunFade( 1, FadeChoice[Index[3]] )
            endif
            set Line[11] = ( "Fade Filters : " + ( ( "(" + ( I2S(Index[3]) + ") " ) ) + FadeName[Index[3]] ) )
            call Board.setText(11,0,Line[11])
        elseif aid == 'A00G' or aid == 'A00H' then
            if aid == 'A00G' then
                set Index[2] = ( Index[2] + 1 )
            else
                set Index[2] = ( Index[2] - 1 )
            endif
            if Index[2] > MaxIndex[2] then
                set Index[2] = MinIndex[2]
            elseif Index[2] < MinIndex[2] then
                set Index[2] = MaxIndex[2]
            endif
            call DestroyLightning( TempLightning )
            if Index[2] != MinIndex[2] then
                set TempLightning = AddLightningEx(LightningChoice[Index[2]], true, 128.500, -12.000, 400, 128.500, -516.00, 400)
            endif
            set Line[12] = ( "Lightning Effects : " + ( ( "(" + ( I2S(Index[2]) + ") " ) ) + LightningName[Index[2]] ) )
            call Board.setText(12,0,Line[12])
        elseif aid == 'A00I' or aid == 'A00J' then
            if aid == 'A00I' then
                set Index[1] = ( Index[1] + 1 )
            else
                set Index[1] = ( Index[1] - 1 )
            endif
            if Index[1] > MaxIndex[1] then
                set Index[1] = MinIndex[1]
            elseif Index[1] < MinIndex[1] then
                set Index[1] = MaxIndex[1]
            endif
            call DestroyUbersplat( bj_lastCreatedUbersplat )
            if Index[1] != MinIndex[1] then
                set bj_lastCreatedUbersplat = CreateUbersplat(XofActor, FinalYofActor, UbersplatChoice[Index[1]], 255, 255, 255, 255, true, true)
                call SetUbersplatRenderAlways( bj_lastCreatedUbersplat, true )
                call ShowUbersplat( bj_lastCreatedUbersplat, true )
            endif
            set Line[13] = ( "Ubersplat Effects : " + ( ( "(" + ( I2S(Index[1]) + ") " ) ) + UbersplatName[Index[1]] ) )
            call Board.setText(13,0,Line[13])
        elseif aid == 'A00L' or aid == 'A00K' then
            if aid == 'A00L' then
                set Index[0] = ( Index[0] + 1 )
            else
                set Index[0] = ( Index[0] - 1 )
            endif
            if Index[0] > MaxIndex[0] then
                set Index[0] = MinIndex[0]
            elseif Index[0] < MinIndex[0] then
                set Index[0] = MaxIndex[0]
            endif
            if Index[0] != MinIndex[0] then
                call SetTerrainType( XofActor, NewYofActor, TerrainChoice[Index[0]], 0, 1, 0 )
            else
                call SetTerrainType( XofActor, NewYofActor, NewTerrainType, 0, 1, 0 )
            endif
            set Line[14] = ( "Terrain Tiles : " + ( ( "(" + ( I2S(Index[0]) + ") " ) ) + TerrainName[Index[0]] ) )
            call Board.setText(14,0,Line[14])
        elseif aid == 'A008' then
            if ShowBoard == true then
                set ShowBoard = false
                call Board.display(true,false)
            else
                set ShowBoard = true
                call Board.display(false,true)
            endif
        elseif aid == 'A002' then
            call ResetMultiboard()
        elseif aid == 'A00C' then
            if uid == 'H002' or uid == 'H003' then
                call ClearSelection()
                call SelectUnit(ControlPanel[1], true)
            else
                call ClearSelection()
                call SelectUnit(ControlPanel[3], true)
            endif
        elseif aid == 'A00D' then
            if uid == 'H002' or uid == 'H003' then
                call ClearSelection()
                call SelectUnit(ControlPanel[0], true)
            else
                call ClearSelection()
                call SelectUnit(ControlPanel[2], true)
            endif
        elseif aid == 'A00N' or aid == 'A00O' then
            if aid == 'A00N' then
                set Index[8] = ( Index[8] + 1 )
            else
                set Index[8] = ( Index[8] - 1 )
            endif
            if Index[8] > MaxIndex[8] then
                set Index[8] = MinIndex[8]
            elseif Index[8] < MinIndex[8] then
                set Index[8] = MaxIndex[8]
            endif
            call DestroyEffect(TempEffect[0])
            if Index[8] != MinIndex[8] then
                set TempEffect[0] = AddSpecialEffectTarget(HelmetChoice[Index[8]], Actor[1], "head")
            endif
            set Line[9] = ( "Helmet Models : " + ( ( "(" + ( I2S(Index[8]) + ") " ) ) + HelmetName[Index[8]] ) )
            call Board.setText(9,0,Line[9])
        elseif aid == 'A00M' or aid == 'A003' then
            if aid == 'A00M' then
                set Index[9] = ( Index[9] + 1 )
            else
                set Index[9] = ( Index[9] - 1 )
            endif
            if Index[9] > MaxIndex[9] then
                set Index[9] = MinIndex[9]
            elseif Index[9] < MinIndex[9] then
                set Index[9] = MaxIndex[9]
            endif
            call DestroyEffect(TempEffect[1])
            if Index[9] != MinIndex[9] then
                set TempEffect[1] = AddSpecialEffectTarget(ChestChoice[Index[9]], Actor[1], "chest")
            endif
            set Line[10] = ( "Chest Models : " + ( ( "(" + ( I2S(Index[9]) + ") " ) ) + ChestName[Index[9]] ) )
            call Board.setText(10,0,Line[10])
        endif
      
        // Nulling the variables
        set u = null
        // --------------------------------------------
  
    endfunction

    private function Init takes nothing returns nothing
        local trigger t = CreateTrigger(  )
        call TriggerRegisterPlayerUnitEvent( t, Player(0), EVENT_PLAYER_UNIT_SPELL_CAST, null)
        call TriggerAddAction( t, function ControlPanelActions )
        set t = null
    endfunction

endscope

i thought it could be because im destroying a variable before the first lightning is ever created but i inserted a boolean check to make sure it only fired once a lightning was displayed but still broke it even with the boolean

example;

JASS:
if LightningBreak == true then
     call DestroyLightning
     set LightningBreak = false
endif
 
Last edited:
Status
Not open for further replies.
Top