HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Help with JASS Trigger

09-07-2007, 02:57 AM#1
Deaod
Well, either i'm writing nonsense in JASS (which is more likely) or I found a bug in PJASS (very unlikely).

This is a trigger i wanted to implement in my Unit Defense Map, based on an old StarCraft Map. The trigger should catch any enter or leave of a unit in a distinct region, add the unit to a unitgroup array and count the units beeing in that group. Once there are more than 10 or 20 units in one group it should remove every unit in that region of the same type and create another in the middle of that region.

After JassCraft crashed one time and i had to recover my trigger from RAM via dump, i finally finished the trigger.
I'd love to get any help, because i can't find anything wrong with this trigger.

It was written mostly in JassCraft, only the init trigger was created by world editor.

Trigger in JASS

globals

Collapse JASS:
globals
    
    trigger gg_trg_HGM_Exchange
    rect gg_rct_HGMASuperunitsExchange
    group array udg_hydraexgrp
    group array udg_marineexgrp
    group array udg_ghostexgrp
    group array udg_archonexgrp
    integer array udg_archonex
    integer array udg_marineex
    integer array udg_ghostex
    integer array udg_hydraex
    
endglobals


InitTrigger

Collapse JASS:
function InitTrig_HGM_Exchange takes nothing returns nothing
    set gg_trg_HGM_Exchange = CreateTrigger(  )
    call TriggerRegisterEnterRectSimple( gg_trg_HGM_Exchange, gg_rct_HGMASuperunitsExchange )
    call TriggerRegisterLeaveRectSimple( gg_trg_HGM_Exchange, gg_rct_HGMASuperunitsExchange )
    call TriggerAddAction( gg_trg_HGM_Exchange, function Trig_HGM_Exchange_Actions )
endfunction


Actions

Collapse JASS:
function Trig_HGM_Exchange_Actions takes nothing returns nothing
local unit uniten=GetEnteringUnit()
local unit unitle=GetLeavingUnit()
local player playeren=GetOwningPlayer(uniten)
local player playerle=GetOwningPlayer(unitle)
local integer playerenid=(GetPlayerId(playeren)+1)
local integer playerleid=(GetPlayerId(playerle)+1)
local integer index=1

//Update globals

    if GetUnitTypeId(uniten)=='z001' then
        set udg_marineex[playerenid]=udg_marineex[playerenid] + 1
        call GroupAddUnit(udg_marineexgrp[playerenid], uniten)
    endif
    if GetUnitTypeId(uniten)=='h000' then
        set udg_ghostex[playerenid]=udg_ghostex[playerenid] + 1
        call GroupAddUnit(udg_ghostexgrp[playerenid], uniten)
    endif
    if GetUnitTypeId(uniten)=='z000' then
        set udg_hydraex[playerenid]=udg_hydraex[playerenid] + 1
        call GroupAddUnit(udg_hydraexgrp[playerenid], uniten)
    endif
    if GetUnitTypeId(uniten)=='h001' then
        set udg_archonex[playerenid]=udg_archonex[playerenid] + 1
        call GroupAddUnit(udg_archonexgrp[playerenid], uniten)
    endif

    if GetUnitTypeId(unitle)=='z001' then
        set udg_marineex[playerleid]=udg_marineex[playerleid] - 1
        call GroupRemoveUnit(udg_marineexgrp[playerleid], uniten)
    endif
    if GetUnitTypeId(unitle)=='h000' then
        set udg_ghostex[playerleid]=udg_ghostex[playerleid] - 1
        call GroupRemoveUnit(udg_ghostexgrp[playerleid], uniten)
    endif
    if GetUnitTypeId(unitle)=='z000' then
        set udg_hydraex[playerleid]=udg_hydraex[playerleid] - 1
        call GroupRemoveUnit(udg_hydraexgrp[playerleid], uniten)
    endif
    if GetUnitTypeId(unitle)=='h001' then
        set udg_archonex[playerleid]=udg_archonex[playerleid] - 1
        call GroupRemoveUnit(udg_archonexgrp[playerleid], uniten)
    endif

//End of Update

    loop

    if udg_marineex[index]>=20 then
        call Trig_HGM_Exchange_Super_Marine()
    endif
    if udg_ghostex[index]>=20 then
        call Trig_HGM_Exchange_Super_Ghost()
    endif
    if udg_hydraex[index]>=20 then
        call Trig_HGM_Exchange_Super_Hydra()
    endif
    if udg_archonex[index]>=10 then
        call Trig_HGM_Exchange_Super_Archon()
    endif
    
    set index=index+1
    exitwhen index>7
    
    endloop
    
    set uniten=null
    set unitle=null
    set playeren=null
    set playerle=null
    

endfunction


FunctionsCalled

Collapse JASS:
function Trig_HGM_Exchange_Super_Archon takes nothing returns nothing
local integer index=1
local location locex=GetRectCenter(gg_rct_HGMASuperunitsExchange)

    loop
    
    if udg_archonex[index]>=10 then
        ForGroup(udg_archonexgrp[index], function Trig_HGM_Exchange_SuperUnit_Remove)
        set udg_archonex[index]=0
        call CreateUnitAtLoc(Player(index-1), 'h00D', locex, 270.0)
    endif

    set index=index+1
    exitwhen index>7
    
    endloop
    
    call RemoveLocation(locex)

endfunction

function Trig_HGM_Exchange_Super_Hydra takes nothing returns nothing
local integer index=1
local location locex=GetRectCenter(gg_rct_HGMASuperunitsExchange)

    loop
    
    if udg_hydraex[index]>=10 then
        ForGroup(udg_hydraexgrp[index], function Trig_HGM_Exchange_SuperUnit_Remove)
        set udg_hydraex[index]=0
        call CreateUnitAtLoc(Player(index-1), 'z006', locex, 270.0)
    endif

    set index=index+1
    exitwhen index>7
    
    endloop
    
    call RemoveLocation(locex)


endfunction

function Trig_HGM_Exchange_Super_Ghost takes nothing returns nothing
local integer index=1
local location locex=GetRectCenter(gg_rct_HGMASuperunitsExchange)

    loop
    
    if udg_ghostex[index]>=10 then
        ForGroup(udg_ghostexgrp[index], function Trig_HGM_Exchange_SuperUnit_Remove)
        set udg_ghostex[index]=0
        call CreateUnitAtLoc(Player(index-1), 'h00E', locex, 270.0)
    endif

    set index=index+1
    exitwhen index>7
    
    endloop
    
    call RemoveLocation(locex)


endfunction

function Trig_HGM_Exchange_Super_Marine takes nothing returns nothing
local integer index=1
local location locex=GetRectCenter(gg_rct_HGMASuperunitsExchange)

    loop
    
    if udg_marineex[index]>=10 then
        ForGroup(udg_marineexgrp[index], function Trig_HGM_Exchange_SuperUnit_Remove)
        set udg_marineex[index]=0
        call CreateUnitAtLoc(Player(index-1), 'z007', locex, 270.0)
    endif

    set index=index+1
    exitwhen index>7
    
    endloop
    
    call RemoveLocation(locex)


endfunction

function Trig_HGM_Exchange_SuperUnit_Remove takes nothing returns nothing
local unit unitp=GetEnumUnit()

    call RemoveUnit(unitp)

endfunction



Thanks in advance

Deaod

€dit: Attached the Trigger. Thats an exact copy of what was checked by PJASS in Jasscraft and newgen.
09-07-2007, 03:00 AM#2
Vexorian
could as well be a jasscraft issue, tried saving it in newgen or WEHelper?
09-07-2007, 03:09 AM#3
Deaod
i did try, returned the same or similar errors in newgen

Deaod

€dit: attached a list of errors jasscraft returned, it cuts off at line 88

Attachment 28758
09-07-2007, 03:29 AM#4
Vexorian
jasshelper only returns one syntax error.

at

Collapse JASS:
    if GetUnitTypeId(uniten]=='h001' then

look closely...

Edit: After changing it got more errors:

Collapse JASS:
ForGroup(udg_archonexgrp[index] , function Trig_HGM_Exchange_SuperUnit_Remove)
missing "call"


"function Trig_HGM_Exchange_SuperUnit_Remove" is also missing from the code you posted, not sure it is missing from your code as well.
09-07-2007, 03:34 AM#5
Deaod
well, i actually copied this error into this post. If you fix it then it should come up with around 80 errors. Updated first post to fix that problem.

€dit: I'll look it up, wait a minute.

€dit 2nd. : Ok, forgot that function; adding it.

€dit 3rd. : uploading new script version

€dit 4th. : Spotted the errors, thanks Vexorian. It was all about the placement of the function called in "ForGroup"

This thread can now be closed.

Deaod