• 🏆 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!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

[JASS] simple jass trigger makes WE crash

Status
Not open for further replies.
Level 8
Joined
Nov 2, 2007
Messages
160
i'm new to jass and i've read Daenlins Tutorial
(http://www.thehelper.net/forums/showthread.php?t=28292http://www.thehelper.net/forums/showthread.php?t=28292)

there is a trigger in point 12 wich makes my WE crash when saving
i made some changes to make the trigger suitable for some beginners Jass tests

this is the trigger:

JASS:
function firecond takes nothing returns boolean
return GetSpellAbilityId()==’A001’
endfunction

function Fire takes nothing returns nothing
local group g
local unit u
local unit cast
local unit dumb
local location p

set cast = GetTriggerUnit()
set p = GetSpellTargetLoc()
set g = GetUnitsInRangeOfLocAll(500.00, p)
loop
      set u = FirstOfGroup(g)
      exitwhen u==null
      if  IsUnitEnemy(u, GetOwningPlayer(cast))==true
      then
      call GroupRemoveUnit(g,u)
      set dumb = CreateUnitAtLoc(GetOwningPlayer(cast), ‘h000’, GetUnitLoc(u), 0.00)
      call IssueTargetOrderBJ(dumb, A002, u)
      call UnitApplyTimedLifeBJ (1.50, ‘BFig’, dumb)
      set dumb = null
      endif
endloop 

set g = null
set u = null
set cast = null
set p = null
endfunction

function InitTrig_Feuer takes nothing returns nothing
local trigger t
set t=CreateTrigger()
call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_SPELL_EFFECT)
call TriggerAddCondition(t, Condition(function firecond))
call TriggerAddAction(t, function Fire)
 
Level 12
Joined
Apr 27, 2008
Messages
1,228
Very simple ;)
You have:
JASS:
loop
      set u = FirstOfGroup(g)
      exitwhen u==null
      if IsUnitEnemy(u, GetOwningPlayer(cast))==true
      then
      call GroupRemoveUnit(g,u)
      set dumb = CreateUnitAtLoc(GetOwningPlayer(cast), ‘h000’, GetUnitLoc(u), 0.00)
call IssueTargetOrderBJ(dumb, A002, u)
      call UnitApplyTimedLifeBJ (1.50, ‘BFig’, dumb)
      set dumb = null
      endif
endloop
Should be:
JASS:
loop
      set u = FirstOfGroup(g)
      exitwhen u==null
      call GroupRemoveUnit(g,u) // line switch here ;)
      if IsUnitEnemy(u, GetOwningPlayer(cast))==true
      then
      set dumb = CreateUnitAtLoc(GetOwningPlayer(cast), ‘h000’, GetUnitLoc(u), 0.00)
call IssueTargetOrderBJ(dumb, A002, u)
      call UnitApplyTimedLifeBJ (1.50, ‘BFig’, dumb)
      set dumb = null
      endif
endloop
If call GroupRemoveUnit(g,u) is inside the "if", then if the unit is not an enemy an infinite loop would occur, resulting in a wc3 crash.
A few other suggestions:
if IsUnitEnemy(u, GetOwningPlayer(cast))==true

Should be:
if IsUnitEnemy(u, GetOwningPlayer(cast))


set dumb = CreateUnitAtLoc(GetOwningPlayer(cast), ‘h000’, GetUnitLoc(u), 0.00)

Should be:
set dumb = CreateUnit(GetOwningPlayer(cast), ‘h000’, GetUnitX(u),GetUnitY(u), 0.00)


call IssueTargetOrderBJ(dumb, A002, u)

Should be:
call IssueTargetOrder(dumb, the_oder_string_of_A002_in_quotation_marks, u)


call UnitApplyTimedLifeBJ (1.50, ‘BFig’, dumb)

Should be:
call UnitApplyTimedLife (dumb, ‘BFig’, 1.50)


No need to "set u = null", as you exit when u==null :)
Also, you leak: you do not destroy the group or remove the locations.

So the trigger should look like this:
JASS:
function firecond takes nothing returns boolean
return GetSpellAbilityId()==’A001’
endfunction

function Fire takes nothing returns nothing
local group g
local unit u
local unit cast
local unit dumb
local location p

set cast = GetTriggerUnit()
set p = GetSpellTargetLoc()
set g = GetUnitsInRangeOfLocAll(500.00, p)
loop
      set u = FirstOfGroup(g)
      exitwhen u==null
      call GroupRemoveUnit(g,u)
      if IsUnitEnemy(u, GetOwningPlayer(cast))
      then
      set dumb = CreateUnit(GetOwningPlayer(cast), ‘h000’, GetUnitX(u),GetUnitY(u), 0.00)
      call IssueTargetOrder(dumb, the_oder_string_of_A002_in_quotation_marks, u)
      call UnitApplyTimedLife (dumb, ‘BFig’, 1.50)
      set dumb = null
      endif
endloop

call DestroyGroup(g)
call RemoveLocation(p)
set g = null
set cast = null
set p = null
endfunction

function InitTrig_Feuer takes nothing returns nothing
local trigger t
set t=CreateTrigger()
call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_SPELL_EFFECT)
call TriggerAddCondition(t, Condition(function firecond))
call TriggerAddAction(t, function Fire)
endfunction

Just some tips ;)
 
Level 12
Joined
Apr 27, 2008
Messages
1,228
Standart WE is not a very good Jass compilation environment(font is awful, does not show errors all the time, crashes when you have simple errors).
I suggest getting Jass New Gen Pack (from wc3campaigns.net).
JASS:
function firecond takes nothing returns boolean
return GetSpellAbilityId()=='A001'
endfunction

function Fire takes nothing returns nothing
local group g
local unit u
local unit cast
local unit dumb
local location p

set cast = GetTriggerUnit()
set p = GetSpellTargetLoc()
set g = GetUnitsInRangeOfLocAll(500.00, p)
loop
      set u = FirstOfGroup(g)
      exitwhen u==null
      call GroupRemoveUnit(g,u)
      if IsUnitEnemy(u, GetOwningPlayer(cast)) then
      set dumb = CreateUnit(GetOwningPlayer(cast), 'h000', GetUnitX(u),GetUnitY(u), 0.00)
      call IssueTargetOrder(dumb, "the_oder_string_of_A002_in_quotation_marks", u)
call UnitApplyTimedLife (dumb, 'BFig', 1.50)
      set dumb = null
      endif
endloop

call DestroyGroup(g)
call RemoveLocation(p)
set g = null
set cast = null
set p = null
endfunction

function InitTrig_Feuer takes nothing returns nothing
local trigger t
set t=CreateTrigger()
call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_SPELL_EFFECT)
call TriggerAddCondition(t, Condition(function firecond))
call TriggerAddAction(t, function Fire)
endfunction
The error was that the "then" after if should be on the same line.
And the symbol you used for ' bugged my WE (didn't recognize it).
 
Level 10
Joined
Aug 19, 2008
Messages
491
i'm new to jass and i've read Daenlins Tutorial
(http://www.thehelper.net/forums/showthread.php?t=28292http://www.thehelper.net/forums/showthread.php?t=28292)

there is a trigger in point 12 wich makes my WE crash when saving
i made some changes to make the trigger suitable for some beginners Jass tests

this is the trigger:

JASS:
function firecond takes nothing returns boolean
return GetSpellAbilityId()==’A001’
endfunction

function Fire takes nothing returns nothing
local group g
local unit u
local unit cast
local unit dumb
local location p

set cast = GetTriggerUnit()
set p = GetSpellTargetLoc()
set g = GetUnitsInRangeOfLocAll(500.00, p)
loop
      set u = FirstOfGroup(g)
      exitwhen u==null
      if  IsUnitEnemy(u, GetOwningPlayer(cast))==true
      then
      call GroupRemoveUnit(g,u)
      set dumb = CreateUnitAtLoc(GetOwningPlayer(cast), ‘h000’, GetUnitLoc(u), 0.00)
      call IssueTargetOrderBJ(dumb, A002, u)
      call UnitApplyTimedLifeBJ (1.50, ‘BFig’, dumb)
      set dumb = null
      endif
endloop 

set g = null
set u = null
set cast = null
set p = null
endfunction

function InitTrig_Feuer takes nothing returns nothing
local trigger t
set t=CreateTrigger()
call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_SPELL_EFFECT)
call TriggerAddCondition(t, Condition(function firecond))
call TriggerAddAction(t, function Fire)

Even though spiwin succeded in telling you how to do, I've found your problem:
you forgot endfunction in InitTrig_Feuer
 
Level 12
Joined
Apr 27, 2008
Messages
1,228
No, the endfunction is there, he just didn't copy it.
And it is present in the code I provided above.
 
Status
Not open for further replies.
Top