• 🏆 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!

[JASS] JASS trigger disabled due to errors

Status
Not open for further replies.
Level 4
Joined
Jan 14, 2017
Messages
75
I looked at the example spell in the Jass tutorial and copied it (In order to familiarize myself with JASS), but my trigger has been disabled due to a truckload of errors (37!). Here is the code (Ignore comments in the code):
JASS:
function Trig_Slash_Actions takes nothing returns nothing
endfunction

//===========================================================================
function InitTrig_Slash takes nothing returns nothing
    set gg_trg_Slash = CreateTrigger(  )
    call TriggerAddAction( gg_trg_Slash, function Trig_Slash_Actions )
endfunction
                              function Trig_Jass_Spell_Actions takes nothing returns nothing
endfunction

//===========================================================================
function InitTrig_Jass_Spell takes nothing returns nothing
    set gg_trg_Jass_Spell = CreateTrigger(  )
    call TriggerAddAction( gg_trg_Jass_Spell, function Trig_Jass_Spell_Actions )
endfunction
function Slash_Condition takes nothing returns boolean
return GetSpellAbilityId() == 'A001' //Compares the ability Id of the ability being cast to this ability Id
endfunction
function Slash_Actions takes nothing returns nothing
local unit caster
local location start_position
local group enemies //It's like a trigger. It's empty initially, and you add stuff to it :)
local unit temp //Position of enemies when they are hit
local integer count = 5 // local means create or set. In this case, local integer count is the maximum number of enemies that can be hit
endfunction            
endfunction
function InitTrig_Slash takes nothing returns nothing
set gg_trg_Slash = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ(gg_trg_Jass_Spell, EVENT_PLAYER_UNIT_SPELL_EFFECT) //Or, whenever a unit starts the effect of the ability, an event registers
call TriggerAddCondition (gg_trg_Jass_Spell, Condition(function Slash_Condition)
call TriggerAddAction(gg_trg_Jass_Spell, function Slash_Actions)
endfunction
call GroupEnumUnitsInRangeOfLoc(enemies, start_position, 500.0, null)
// GroupEnumUnitsInRangeOfLoc takes a group, a location, a radius, and a boolexpr (a condition, kind of) and then gets units within that radius and adds them to our group
loop
set temp =   FirstOfGroup(enemies)
exitwhen temp = null or count = 0
if IsUnitEnemy(temp, GetOwningPlayer(caster)) then
set temp_loc = GetUnitLoc(temp)
call SetUnitPositionLoc(caster,temp_loc)
call UnitDamageTarget (caster, temp, 50, true, false ,ATTACK_TYPE_CHAOS,DAMAGE_TYPE_NORMAL, null)
set count = count - 1
call RemoveLocation(temp_loc)
endif
call GroupRemoveUnit(enemies, temp)
endloop
call RemoveLocation (start_position)
call DestroyGroup(enemies)
set caster = null
set start_position = null
set enemies = null
set temp=null
local start_position = GetUnitLoc(caster)
endfunction        
function InitTrig_Jass_Spell takes nothing returns nothing
set gg_trg_Jass_Spell = CreateTrigger()
call TriggerRegisterAnyUnitEvenBJ (gg_trg_Jass_Spell, EVENT_PLAYER_UNIT_SPELL_EFFECT)
call TriggerAddCondition (gg_trg_Jass_Spell, Condition (function Slash_Condition)
call TriggerAddAction (gg_trg_Slash, function Slash_Actions)
endloop
endfunction
If you're wondering why I put the code in JavaScript, it was because I don't have the option to put it in JASS code.

Please explain what I did wrong briefly (Don't explain every single error, for convenience).
Thank you! I'm sorry that I post so many questions. :ar:
 
Last edited:
functions have to be unique, means each must have an different name.
locals can only be created at the start of a function and only accessed in the function they are created.
to use locals in other functions you have to hand them over as arguments and defining them after the takes instead of writing nothing.
functionhead + endfunction surround an code block, 1 alone makes not so much sense.
function head = function name takes nothing returns nothing​
function head
local block
code
morecode
..​
endfunction

function head
local block
code
morecode
..​
endfunction


Global Variables like gg, udg have to exist before the can be used.
gg are automatic generated globals based on Things created with editor.
udg_ with the variable editor

post jass with [code=jass][/code].
 
Last edited:
Level 13
Joined
May 10, 2009
Messages
868
JASS:
function HandItToMe takes unit arg returns nothing
    call KillUnit(arg) // what a waste
endfunction

function No takes nothing returns nothing
    local unit u = CreateUnit(Player(0), 'hpea', 0., 0., 270.) // It creates a peasant (hpea) for player red (0) at the center of the map.
    call HandItToMe(u)
    set u = null
endfunction
 
Original code:
JASS:
function Trig_Slash_Actions takes nothing returns nothing
endfunction

//===========================================================================
function InitTrig_Slash takes nothing returns nothing
    set gg_trg_Slash = CreateTrigger(  )
    call TriggerAddAction( gg_trg_Slash, function Trig_Slash_Actions )
endfunction
                              function Trig_Jass_Spell_Actions takes nothing returns nothing
endfunction

//===========================================================================
function InitTrig_Jass_Spell takes nothing returns nothing
    set gg_trg_Jass_Spell = CreateTrigger(  )
    call TriggerAddAction( gg_trg_Jass_Spell, function Trig_Jass_Spell_Actions )
endfunction
function Slash_Condition takes nothing returns boolean
return GetSpellAbilityId() == 'A001' //Compares the ability Id of the ability being cast to this ability Id
endfunction
function Slash_Actions takes nothing returns nothing
local unit caster
local location start_position
local group enemies //It's like a trigger. It's empty initially, and you add stuff to it :)
local unit temp //Position of enemies when they are hit
local integer count = 5 // local means create or set. In this case, local integer count is the maximum number of enemies that can be hit
endfunction          
endfunction
function InitTrig_Slash takes nothing returns nothing
set gg_trg_Slash = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ(gg_trg_Jass_Spell, EVENT_PLAYER_UNIT_SPELL_EFFECT) //Or, whenever a unit starts the effect of the ability, an event registers
call TriggerAddCondition (gg_trg_Jass_Spell, Condition(function Slash_Condition)
call TriggerAddAction(gg_trg_Jass_Spell, function Slash_Actions)
endfunction
call GroupEnumUnitsInRangeOfLoc(enemies, start_position, 500.0, null)
// GroupEnumUnitsInRangeOfLoc takes a group, a location, a radius, and a boolexpr (a condition, kind of) and then gets units within that radius and adds them to our group
loop
set temp =   FirstOfGroup(enemies)
exitwhen temp = null or count = 0
if IsUnitEnemy(temp, GetOwningPlayer(caster)) then
set temp_loc = GetUnitLoc(temp)
call SetUnitPositionLoc(caster,temp_loc)
call UnitDamageTarget (caster, temp, 50, true, false ,ATTACK_TYPE_CHAOS,DAMAGE_TYPE_NORMAL, null)
set count = count - 1
call RemoveLocation(temp_loc)
endif
call GroupRemoveUnit(enemies, temp)
endloop
call RemoveLocation (start_position)
call DestroyGroup(enemies)
set caster = null
set start_position = null
set enemies = null
set temp=null
local start_position = GetUnitLoc(caster)
endfunction      
function InitTrig_Jass_Spell takes nothing returns nothing
set gg_trg_Jass_Spell = CreateTrigger()
call TriggerRegisterAnyUnitEvenBJ (gg_trg_Jass_Spell, EVENT_PLAYER_UNIT_SPELL_EFFECT)
call TriggerAddCondition (gg_trg_Jass_Spell, Condition (function Slash_Condition)
call TriggerAddAction (gg_trg_Slash, function Slash_Actions)
endloop
endfunction

New code: (Script Fixing) (Partial)
JASS:
function Trig_Slash_Actions takes nothing returns nothing
endfunction

function InitTrig_Slash takes nothing returns nothing
    set gg_trg_Slash = CreateTrigger(  )
    call TriggerAddAction( gg_trg_Slash, function Trig_Slash_Actions )
endfunction
                             
function Trig_Jass_Spell_Actions takes nothing returns nothing
endfunction

function InitTrig_Jass_Spell takes nothing returns nothing
    set gg_trg_Jass_Spell = CreateTrigger(  )
    call TriggerAddAction( gg_trg_Jass_Spell, function Trig_Jass_Spell_Actions )
endfunction

function Slash_Condition takes nothing returns boolean
    return GetSpellAbilityId() == 'A001'
endfunction

function Slash_Actions takes nothing returns nothing
    local unit caster
    local unit temp
    local location start_position = GetUnitLoc(caster)
    local group enemies
    local integer count = 5

    call GroupEnumUnitsInRangeOfLoc(enemies, start_position, 500.0, null)
    loop
        set temp = FirstOfGroup(enemies)
        exitwhen temp == null or count == 0

        if IsUnitEnemy(temp, GetOwningPlayer(caster)) then
            set temp_loc = GetUnitLoc(temp)
            call SetUnitPositionLoc(caster,temp_loc)
            call UnitDamageTarget (caster, temp, 50, true, false ,ATTACK_TYPE_CHAOS,DAMAGE_TYPE_NORMAL, null)
            set count = count - 1
            call RemoveLocation(temp_loc)
        endif
        call GroupRemoveUnit(enemies, temp)
    endloop
    call RemoveLocation (start_position)
    call DestroyGroup(enemies)
    set caster = null
    set start_position = null
    set enemies = null
    set temp=null
    set start_position = null
endfunction

function InitTrig_Slash takes nothing returns nothing
    set gg_trg_Slash = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(gg_trg_Jass_Spell, EVENT_PLAYER_UNIT_SPELL_EFFECT)
    call TriggerAddCondition (gg_trg_Jass_Spell, Condition(function Slash_Condition)
    call TriggerAddAction(gg_trg_Jass_Spell, function Slash_Actions)
endfunction
   
function InitTrig_Jass_Spell takes nothing returns nothing
    set gg_trg_Jass_Spell = CreateTrigger()
    call TriggerRegisterAnyUnitEvenBJ (gg_trg_Jass_Spell, EVENT_PLAYER_UNIT_SPELL_EFFECT)
    call TriggerAddCondition (gg_trg_Jass_Spell, Condition (function Slash_Condition)
    call TriggerAddAction (gg_trg_Slash, function Slash_Actions)
endfunction

(Script Optimizing) (Full)
JASS:
function Slash_Actions takes nothing returns boolean
    local unit caster
    local unit temp
    local group enemies
    local integer count = 5

    if GetSpellAbilityId() == 'A001' then
        set caster = GetTriggerUnit()
        set enemies = CreateGroup()
        call GroupEnumUnitsInRange(enemies, GetUnitX(caster), GetUnitY(caster), 500.0, null)
        loop
            set temp = FirstOfGroup(enemies)
            exitwhen temp == null or count == 0

            if IsUnitEnemy(temp, GetOwningPlayer(caster)) then
                call SetUnitX(caster, GetUnitX(temp))
                call SetUnitY(caster, GetUnitY(temp))
                call UnitDamageTarget (caster, temp, 50, true, false ,ATTACK_TYPE_CHAOS,DAMAGE_TYPE_NORMAL, null)
                set count = count - 1
            endif
            call GroupRemoveUnit(enemies, temp)
        endloop
        call DestroyGroup(enemies)
        set caster = null
        set temp=null
        set enemies = null
    endif
    return false
endfunction

function InitTrig_Slash takes nothing returns nothing
    set gg_trg_Slash = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(gg_trg_Slash, EVENT_PLAYER_UNIT_SPELL_EFFECT)
    call TriggerAddCondition (gg_trg_Slash, Filter(function Slash_Actions))
endfunction
 
Last edited:
Level 4
Joined
Jan 14, 2017
Messages
75
Is it solved?: )
Nope. I copied and pasted in the spell, but I still get a truckload of errors. I tried to download vJass (do I need it to run the code?) and my AntiVirus said I was risking downloading a Trojan virus on my computer.
By the way, I didn't realize that indenting code lines was important! LOL! I thought it was just to clarify things for people reading it.

EDIT: I got it working. I just needed to delete the custom text already there. THANKS!
EDIT 2: How do I make the spell icon show up (using JASS)? It doesn't appear, and I am using Channel as a dummy ability.
 
Last edited:
Level 13
Joined
May 10, 2009
Messages
868
You need to render Channel ability as visible. Go to the object editor, select it and change the Data - Options field to Visible.
Sem título.png
 
Nope. I copied and pasted in the spell, but I still get a truckload of errors. I tried to download vJass (do I need it to run the code?) and my AntiVirus said I was risking downloading a Trojan virus on my computer.
By the way, I didn't realize that indenting code lines was important! LOL! I thought it was just to clarify things for people reading it.

EDIT: I got it working. I just needed to delete the custom text already there. THANKS!
EDIT 2: How do I make the spell icon show up (using JASS)? It doesn't appear, and I am using Channel as a dummy ability.

Indenting would make things clearer both to the reader and the coder. If used internally, it is to your preference.
The program is usually mislabelled as a trojan virus by Antiviruses because of how it works but don't be afraid, it is harmless.

Answer: {EDIT 2}

You need to render Channel ability as visible. Go to the object editor, select it and change the Data - Options field to Visible.
sem-t%C3%ADtulo-png.277830
 
Last edited:
Status
Not open for further replies.
Top