Trigger in JASS-->Crash

Erkki2

New Member
Reaction score
0
I created my first trigger in JASS. Actually I converted it from GUI trigger, but I added local variables and used timer instead of wait. At first there were of course some errors, but I fixed them. Then I thought to make that trigger local instead of local, well, then the WE crashed. I can't find any mistakes from my code, so I don't know what's wrong. Here's the code
Code:
function Cond takes nothing returns boolean
    if ( not ( GetSpellAbilityId() == 'A039' ) ) then
        return false
    endif
    return true
endfunction

function Trig_Tri_Attack_Func004Func001Func005C takes nothing returns boolean
    if ( not ( GetHeroLevel(GetTriggerUnit()) >= 60 ) ) then
        return false
    endif
    return true
endfunction

function Trig_Tri_Attack_Func004Func001Func006C takes nothing returns boolean
    if ( not ( GetHeroLevel(GetTriggerUnit()) >= 80 ) ) then
        return false
    endif
    return true
endfunction

function Trig_Tri_Attack_Func004Func002Func005C takes nothing returns boolean
    if ( not ( GetHeroLevel(GetTriggerUnit()) >= 60 ) ) then
        return false
    endif
    return true
endfunction

function Trig_Tri_Attack_Func004Func002Func006C takes nothing returns boolean
    if ( not ( GetHeroLevel(GetTriggerUnit()) >= 80 ) ) then
        return false
    endif
    return true
endfunction

function Trig_Tri_Attack_Func004Func003Func005C takes nothing returns boolean
    if ( not ( GetHeroLevel(GetTriggerUnit()) >= 60 ) ) then
        return false
    endif
    return true
endfunction

function Trig_Tri_Attack_Func004Func003Func006C takes nothing returns boolean
    if ( not ( GetHeroLevel(GetTriggerUnit()) >= 80 ) ) then
        return false
    endif
    return true
endfunction

function Trig_Tri_Attack_Actions takes nothing returns nothing
    local unit u
    set u = GetTriggerUnit()
        set bj_forLoopBIndex = 1
        set bj_forLoopBIndexEnd = 10
        loop
            exitwhen bj_forLoopBIndex > bj_forLoopBIndexEnd
            call CreateNUnitsAtLoc( 1, 'n000', GetOwningPlayer(u), PolarProjectionBJ(GetUnitLoc(u), ( 400.00 - ( 40.00 * I2R(GetForLoopIndexB()) ) ), ( 0.00 + ( 10.00 * I2R(GetForLoopIndexA()) ) )), bj_UNIT_FACING )
            call UnitApplyTimedLifeBJ( 5.00, 'BTLF', GetLastCreatedUnit() )
            call ShowUnitHide( GetLastCreatedUnit() )
            call UnitAddAbilityBJ( 'A03E', GetLastCreatedUnit() )
            if ( Trig_Tri_Attack_Func004Func001Func005C() ) then
                call IncUnitAbilityLevelSwapped( 'A03E', GetLastCreatedUnit() )
            else
            endif
            if ( Trig_Tri_Attack_Func004Func001Func006C() ) then
                call IncUnitAbilityLevelSwapped( 'A03E', GetLastCreatedUnit() )
            else
            endif
            call IssueImmediateOrderBJ( GetLastCreatedUnit(), "fanofknives" )
            set bj_forLoopBIndex = bj_forLoopBIndex + 1
        endloop
        set bj_forLoopBIndex = 1
        set bj_forLoopBIndexEnd = 10
        loop
            exitwhen bj_forLoopBIndex > bj_forLoopBIndexEnd
            call CreateNUnitsAtLoc( 1, 'n000', GetOwningPlayer(u), PolarProjectionBJ(GetUnitLoc(u), ( 400.00 - ( 40.00 * I2R(GetForLoopIndexB()) ) ), ( 120.00 + ( 10.00 * I2R(GetForLoopIndexA()) ) )), bj_UNIT_FACING )
            call UnitApplyTimedLifeBJ( 5.00, 'BTLF', GetLastCreatedUnit() )
            call ShowUnitHide( GetLastCreatedUnit() )
            call UnitAddAbilityBJ( 'A03F', GetLastCreatedUnit() )
            if ( Trig_Tri_Attack_Func004Func002Func005C() ) then
                call IncUnitAbilityLevelSwapped( 'A03F', GetLastCreatedUnit() )
            else
            endif
            if ( Trig_Tri_Attack_Func004Func002Func006C() ) then
                call IncUnitAbilityLevelSwapped( 'A03F', GetLastCreatedUnit() )
            else
            endif
            call IssueImmediateOrderBJ( GetLastCreatedUnit(), "fanofknives" )
            set bj_forLoopBIndex = bj_forLoopBIndex + 1
        endloop
        set bj_forLoopBIndex = 1
        set bj_forLoopBIndexEnd = 10
        loop
            exitwhen bj_forLoopBIndex > bj_forLoopBIndexEnd
            call CreateNUnitsAtLoc( 1, 'n000', GetOwningPlayer(u), PolarProjectionBJ(GetUnitLoc(u), ( 400.00 - ( 40.00 * I2R(GetForLoopIndexB()) ) ), ( 240.00 + ( 10.00 * I2R(GetForLoopIndexA()) ) )), bj_UNIT_FACING )
            call UnitApplyTimedLifeBJ( 5.00, 'BTLF', GetLastCreatedUnit() )
            call ShowUnitHide( GetLastCreatedUnit() )
            call UnitAddAbilityBJ( 'A03D', GetLastCreatedUnit() )
            if ( Trig_Tri_Attack_Func004Func003Func005C() ) then
                call IncUnitAbilityLevelSwapped( 'A03D', GetLastCreatedUnit() )
            else
            endif
            if ( Trig_Tri_Attack_Func004Func003Func006C() ) then
                call IncUnitAbilityLevelSwapped( 'A03D', GetLastCreatedUnit() )
            else
            endif
            call IssueImmediateOrderBJ( GetLastCreatedUnit(), "fanofknives" )
            set bj_forLoopBIndex = bj_forLoopBIndex + 1
        endloop
    set u = null
endfunction

function Timer takes nothing returns nothing
    local timer t
    set t = CreateTimer()
    call TimerStart(t,0.01,true,function Trig_Tri_Attack_Actions)
    call TriggerSleepAction(10.00)
    call DestroyTimer(t)
    [B]set t = null[/B] *
andfunction

function InitTrig_trigger takes nothing returns nothing
    local trigger t
    set t= CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ( t, EVENT_PLAYER_UNIT_SPELL_EFFECT)
    call TriggerAddCondition(t, Condition(function Cond))
    call TriggerAddAction(t, function Timer)
endfunction
Inside the loops everything is allright. *Before it crashed, it said there was an error. Why does WE crash?
 

Exide

I am amazingly focused right now!
Reaction score
448
You should use JASS-tags for JASS code.
Also you should post this in the JASS forum.

JASS:

function Timer takes nothing returns nothing
    local timer t
    set t = CreateTimer()
    call TimerStart(t,0.01,true,function Trig_Tri_Attack_Actions)
    call TriggerSleepAction(10.00)
    call DestroyTimer(t)
    set t = null *      //Remove the star.
andfunction      //Typo.


Has a typo, says andfunction. Change it to endfunction, and see what happens.
Also, remove the star from set t = null *

EDIT:
All these functions:
JASS:

function Trig_Tri_Attack_Func004Func001Func005C takes nothing returns boolean
    if ( not ( GetHeroLevel(GetTriggerUnit()) >= 60 ) ) then
        return false
    endif
    return true
endfunction


Could be this:
JASS:

function Trig_Tri_Attack_Func004Func001Func005C takes nothing returns boolean
    return ( GetHeroLevel(GetTriggerUnit()) >= 60 )
endfunction


To make it even shorter, you could do this:

JASS:

    if ( Trig_Tri_Attack_Func004Func001Func005C() ) then


==

JASS:

    if ( GetHeroLevel(GetTriggerUnit()) >= 60 ) then


and remove the:

JASS:

function Trig_Tri_Attack_Func004Func001Func005C takes nothing returns boolean
    return ( GetHeroLevel(GetTriggerUnit()) >= 60 )
endfunction


completely.
 

Erkki2

New Member
Reaction score
0
I fixed the typo, and WE doesn't crash anymore. I made the code simplier by removing if structures. Now there's just one problem: it doesn't create any unit. Here's the fixed code:
JASS:
function Cond takes nothing returns boolean
    if ( not ( GetSpellAbilityId() == 'A039' ) ) then
        return false
    endif
    return true
endfunction

function Trig_Tri_Attack_Actions takes nothing returns nothing
    local unit u
    local integer i
    set u = GetTriggerUnit()
        set bj_forLoopBIndex = 1
        set bj_forLoopBIndexEnd = 10
        loop
            exitwhen bj_forLoopBIndex > bj_forLoopBIndexEnd
            call CreateNUnitsAtLoc( 1, 'n000', GetOwningPlayer(u), PolarProjectionBJ(GetUnitLoc(u), ( 400.00 - ( 40.00 * I2R(GetForLoopIndexB()) ) ), ( 0.00 + ( 10.00 * i ) )), bj_UNIT_FACING )
            call UnitApplyTimedLifeBJ( 5.00, 'BTLF', GetLastCreatedUnit() )
            call UnitAddAbilityBJ( 'A03E', GetLastCreatedUnit() )
            call IssueImmediateOrderBJ( GetLastCreatedUnit(), "fanofknives" )
            set bj_forLoopBIndex = bj_forLoopBIndex + 1
        endloop
        set bj_forLoopBIndex = 1
        set bj_forLoopBIndexEnd = 10
        loop
            exitwhen bj_forLoopBIndex > bj_forLoopBIndexEnd
            call CreateNUnitsAtLoc( 1, 'n000', GetOwningPlayer(u), PolarProjectionBJ(GetUnitLoc(u), ( 400.00 - ( 40.00 * I2R(GetForLoopIndexB()) ) ), ( 120.00 + ( 10.00 * i ) )), bj_UNIT_FACING )
            call UnitApplyTimedLifeBJ( 5.00, 'BTLF', GetLastCreatedUnit() )
            call UnitAddAbilityBJ( 'A03F', GetLastCreatedUnit() )
            call IssueImmediateOrderBJ( GetLastCreatedUnit(), "fanofknives" )
            set bj_forLoopBIndex = bj_forLoopBIndex + 1
        endloop
        set bj_forLoopBIndex = 1
        set bj_forLoopBIndexEnd = 10
        loop
            exitwhen bj_forLoopBIndex > bj_forLoopBIndexEnd
            call CreateNUnitsAtLoc( 1, 'n000', GetOwningPlayer(u), PolarProjectionBJ(GetUnitLoc(u), ( 400.00 - ( 40.00 * I2R(GetForLoopIndexB()) ) ), ( 240.00 + ( 10.00 * i ) )), bj_UNIT_FACING )
            call UnitApplyTimedLifeBJ( 5.00, 'BTLF', GetLastCreatedUnit() )
            call UnitAddAbilityBJ( 'A03D', GetLastCreatedUnit() )
            call IssueImmediateOrderBJ( GetLastCreatedUnit(), "fanofknives" )
            set bj_forLoopBIndex = bj_forLoopBIndex + 1
        endloop
    set i = i + 1
    set u = null
endfunction

function Timer takes nothing returns nothing
    local timer t
    set t = CreateTimer()
    call TimerStart(t,0.01,true,function Trig_Tri_Attack_Actions)
    call TriggerSleepAction(10.00)
    call DestroyTimer(t)
    set t = null
endfunction

function InitTrig_Tri_Attack takes nothing returns nothing
    local trigger t
    set t= CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ( t, EVENT_PLAYER_UNIT_SPELL_EFFECT)
    call TriggerAddCondition(t, Condition(function Cond))
    call TriggerAddAction(t, function Timer)
endfunction
 

Exide

I am amazingly focused right now!
Reaction score
448
Your trigger is full of BJ's and leaks.
Why have you converted it to JASS? :p
You should do this in GUI, it might be easier to read as well..
Why are you looping the same thing 3 times over?
 

Erkki2

New Member
Reaction score
0
Actually, it's not the same thing. They create units 120 degrees to different directions, so they are like in a triangle. Also, The abilities are different, one with fire, one with ice and one with lightning effect. I thought to make this in JASS because it's impossible to make this MUI in GUI. And I'll try to remove leak if I get it work first.
 

Erkki2

New Member
Reaction score
0
Ok, I'll download that. There's still one question: I guess I won't need it in this trigger, but it's important to know. So, Where should I copy the script when I'm using Kattana's local handle vars?
 

Exide

I am amazingly focused right now!
Reaction score
448
Here's how I would've done it:
JASS:

function Cond takes nothing returns boolean
    return ( GetSpellAbilityId() == 'A039' )
endfunction

function Trig_Tri_Attack_Actions takes nothing returns nothing
    local unit u = GetTriggerUnit()
    local integer loopnr = 1
    local location loc
    local real angle
    local integer i
    local integer whatability
    
    loop
        exitwhen loopnr > 30
        
        if (loopnr > 0) then
            set angle = 0.00
            set whatability = 'A03E'
        elseif (loopnr > 10) then
            set angle = 120.00
            set whatability = 'A03F'
        elseif (loopnr > 20) then
            set angle = 240.00
            set whatability = 'A03D'
        endif
        
        set loc = GetUnitLoc(u)        
        call CreateNUnitsAtLoc( 1, 'n000', GetOwningPlayer(u), PolarProjectionBJ(loc, ( 400.00 - ( 40.00 * I2R(loopnr) ) ), ( angle + ( 10.00 * i ) )), 270.00 )
        call UnitApplyTimedLife( GetLastCreatedUnit(), 'BTLF', 5.00 )
        call UnitAddAbility( GetLastCreatedUnit(), whatability )
        call IssueImmediateOrder( GetLastCreatedUnit(), "fanofknives" )
        
        set i = i + 1
        set loopnr = loopnr + 1
    endloop
    
    set u = null
endfunction

function Timer takes nothing returns nothing
    local timer t
    set t = CreateTimer()
    call TimerStart(t,0.01,true,function Trig_Tri_Attack_Actions)
    call TriggerSleepAction(10.00)
    call DestroyTimer(t)
    set t = null
endfunction

function InitTrig_Tri_Attack takes nothing returns nothing
    local trigger t = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ( t, EVENT_PLAYER_UNIT_SPELL_EFFECT)
    call TriggerAddCondition(t, Condition(function Cond))
    call TriggerAddAction(t, function Timer)
endfunction


Didn't test it, so it might not work. But I'm sure you can work that out. :p
EDIT: If those three different abilities are the same, but with different damage, AoE, whatever. You should use the same ability with three different levels.


> So, Where should I copy the script when I'm using Kattana's local handle vars?
-I'm guessing in the "trigger", in the trigger editor, that is at the very top of your list. -The one with the same name as your map, and that has a different icon than all the other triggers.
 

Viikuna

No Marlo no game.
Reaction score
265
Im not sure if Handle Vars is a good option anymore.. I personally have never used it. There is a lot of gamecache based systems, maybe you should try Table (link) ?

Also, if you are using NewGen and vJass, you should learn how tu use structs, they are really good way store your data.
 

Erkki2

New Member
Reaction score
0
I downloaded NewGen, but I get error when I try to run the editor. It says I should check that Warcraft is not running and that I have the CD in the drive.
Edit: And how to use Table?
Edit2: NewGen works with warcraft version 1.21b, but not with the newer version. Problem is fixed if I use old version for making maps and new version for playing.
 
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