• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[JASS] Register Events with a loop?

Status
Not open for further replies.
Level 2
Joined
Feb 22, 2009
Messages
24
Is it possible to register all "Unit_enters_Region" events to one trigger?

Tryed it and ... it doesnt fire...maybe i made a mistake, or its just a limitation the engine has ...

udg_zGebiete is filled with Rects...

JASS:
globals
  rect array udg_zGebiete
endglobals

function InitTrig_Movement takes nothing returns nothing
  local trigger Movement = CreateTrigger(  )
  local integer i = 0

  loop
    exitwhen i>90 //for all Rects of all Players 
      call TriggerRegisterEnterRectSimple(Movement, udg_zGebiete[i])
    set i = i+1
  endloop
  call TriggerAddCondition( Movement, Condition( function Trig_Move_Cond ) )
  call TriggerAddAction( Movement, function Trig_Move_Actions )
  
  set i = 0
  call DestroyTrigger(Movement)
  set Movement = null
endfunction
 
Level 2
Joined
Feb 22, 2009
Messages
24
Doesn't work when i remove those lines...
To immediate destroying: I thought i destroy the trigger after i called the conditions and the actions...
IF i can register the event in a loop...


btw: just tried it in a global trigger...also no result
 
Level 2
Joined
Feb 22, 2009
Messages
24
Here the whole Code...but i dont even get the text displayed = no trig.action
enhanced a lil testmap...

JASS:
function Trig_Move_Cond takes nothing returns boolean
  return true //later
endfunction


function Trig_Move_Actions takes nothing returns nothing   
  local integer i = 0
  local region triggeringRect = GetTriggeringRegion()
  local integer triggeringRectId
  local unit triggeringUnit = GetTriggerUnit()
  local boolean good = false

// ---function---
  call DisplayTimedTextToForce(GetPlayersAll(),20, "Inside") 

  //Get triggeringRectId
  set i = 0
  loop  
    exitwhen i>3   //(good == true)
      if (triggeringRect == udg_zGebiete[i]) then
        set triggeringRectId = i
        //set good = true
      endif
    set i = i+1
  endloop
  
  //Show result
  call DisplayTimedTextToForce(GetPlayersAll(),20,I2S(triggeringRectId))
  
  //Its NOT the last point = next spawn moving!
  if ModuloInteger(triggeringRectId, 10) != 9 then  //All Spawns are x0 (x=player no) i.e. red: 00, blue: 10
    call IssuePointOrderLoc( triggeringUnit, "move", GetRectCenter(udg_zGebiete[triggeringRectId+1]) )
    return //Get out here ;) (we will see if it leaks then)
  endif



//---clean up---
  set triggeringUnit = null
  set triggeringRect = null
endfunction

//===========================================================================
function InitTrig_Movement takes nothing returns nothing
  local trigger Movement = CreateTrigger(  )
  local integer i = 0

  loop
    exitwhen i>3 //for all Rects of all Players 
      call TriggerRegisterEnterRectSimple(Movement, udg_zGebiete[i])
    set i = i+1
  endloop

  call TriggerAddCondition( Movement, Condition( function Trig_Move_Cond ) )
  call TriggerAddAction( Movement, function Trig_Move_Actions )
  
endfunction

The Question is: Can i register events in a loop...and can i register events with a variable as parameter ...
 

Attachments

  • runningtest.w3x
    16.1 KB · Views: 32
Level 13
Joined
Mar 16, 2008
Messages
941
For sure you can register events in a loop, why shouldn't you?
a) it is completly logic
b)
JASS:
function TriggerRegisterAnyUnitEventBJ takes trigger trig, playerunitevent whichEvent returns nothing
    local integer index

    set index = 0
    loop
        call TriggerRegisterPlayerUnitEvent(trig, Player(index), whichEvent, null)

        set index = index + 1
        exitwhen index == bj_MAX_PLAYER_SLOTS
    endloop
endfunction
Blizzard and any Jass Coder does it for any spell ;)
The problem is that udg_zGebiete has to be filled before this trigger is created...
I'd write the initialization in the same function then this loop :O
 
Level 2
Joined
Feb 22, 2009
Messages
24
Okay...it works when i set the global directly in front of the loop...it works NOT when i set those in the map init!! ( +rep )

i got 2 problems left:
(1) Those Variables (udg_zGebiete) have to be global (cause i cannot give parameters in actions...-.-*) - This trigger will (in the game) run ca. every 0.1-0.4 seconds... I think its not a good idea to "re-"set the rects in this short periods! I wanted to use this method to save recources (and writing work...not to meantion the reuse value)
I also wanted to set the variables not by coordinates, but by regions (easier to re-adjust in the WE)

(2) How can i react to the Event ... i get the unit, but not the Rect / Region.
The function GetTriggeringRegion doesnt work and there is no rect-pendant. Maybe a workaround with GetUnitsInRectAll...but that means 2 additional useless, recourcetaken loops. Looks like i have to rely on handle vars, but they will also require a lot of loops ... If there is any other solution, i would be pleased.
 
Level 14
Joined
Nov 18, 2007
Messages
816
it works NOT when i set those in the map init!!
Thats because the trigger thats setting those globals is running after you register those EnterRect events.

If you are using JNGP already, then you are free to declare globals wherever you want to. That should also remove the need of LHV.

JASS:
local real x=GetUnitX(triggeringUnit)
local real y=GetUnitY(triggeringUnit)
    
    loop
        exitwhen i>3 //(good == true)
        if x<=GetRectMaxX(udg_zGebiete[i]) and x>=GetRectMinX(udg_zGebiete[i]) and y<=GetRectMaxY(udg_zGebiete[i]) and y>=GetRectMinY(udg_zGebiete[i]) then
            set triggeringRectId = i
            exitwhen true
            //set good = true
        endif
        set i = i+1
    endloop
 
@Deaod
I don't think he/she is using JNGP already, he/she just put that global in a global block to show us he declared it.

@Iluya
1) Those variables can still be global and set in the trigger initialisation.

2) I think, rather than the current array of rects you are using, you should convert them to regions and store regions in the array. That way you will be able to compare them to GetTriggeringRegion().
 
Status
Not open for further replies.
Top