• 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] Multiple Triggers overlay their values?

Status
Not open for further replies.
Level 2
Joined
Feb 22, 2009
Messages
24
I am working on a easy expandable auto-movement system... Usable for mainly TDs or long routes i.e. patrols use.

I have one event handling trigger for that, which creates one Trigger for every event (i hope :p)! The Units run like they should ... most time...

sometimes all units at a specific Waypoint gets the result -3 and going to the wrong WP (Center of Map, which is default i think).

Question is now: Why do they SOMETIMES get the wrong results?
Code:

JASS:
globals
  rect array udg_zRegion
  integer udg_yRegionsPerPlayer
  integer udg_yPlayerCount
  integer udg_zRegionCount
  integer udg_UnitsToSpawn
  trigger gg_trg_Spawn
endglobals

function SetRects takes nothing returns nothing
  set udg_zRegion[1] = Rect( -2592.0, 2048.0, -2048.0, 2560.0 )
  set udg_zRegion[2] = Rect( -1056.0, 2016.0, -480.0, 2592.0 )
  set udg_zRegion[3] = Rect( -1056.0, 992.0, -480.0, 1536.0 )
  set udg_zRegion[4] = Rect( -2624.0, 992.0, -2048.0, 1568.0 )
  set udg_zRegion[5] = Rect( -896.0, 2432.0, -640.0, 2560.0 )
  set udg_zRegion[6] = Rect( 0.0, 2304.0, 128.0, 2560.0 )
  set udg_zRegion[7] = Rect( -128.0, 1664.0, 128.0, 1792.0 )
  set udg_zRegion[8] = Rect( -896.0, 1664.0, -768.0, 1920.0 )
  set udg_zRegion[9] = Rect( -2560.0, 1152.0, -2304.0, 1280.0 )
  set udg_zRegion[10] = Rect( -1664.0, 1024.0, -1536.0, 1280.0 )
  set udg_zRegion[11] = Rect( -1792.0, 384.0, -1536.0, 512.0 )
  set udg_zRegion[12] = Rect( -2560.0, 384.0, -2432.0, 640.0 )
  set udg_zRegion[13] = Rect( -896.0, 1152.0, -640.0, 1280.0 )
  set udg_zRegion[14] = Rect( 0.0, 1024.0, 128.0, 1280.0 )
  set udg_zRegion[15] = Rect( -128.0, 384.0, 128.0, 512.0 )
  set udg_zRegion[16] = Rect( -896.0, 384.0, -768.0, 640.0 )

  set udg_zRegionCount = 16      // the highest number in the array!
  set udg_yPlayerCount = 4       // We have to start with 1 .. mod works for (x!=0)
  set udg_yRegionsPerPlayer = 4  // 1 Red, 2 Blue ... etc
endfunction
      
//EndGlobals    

function Trig_Spawn_Actions takes nothing returns nothing
local integer i = 1
local integer k = 1

loop
 exitwhen k>udg_UnitsToSpawn // i suggest 1-9

  set i=1
  loop 
    exitwhen i>udg_zRegionCount
      if ModuloInteger(i, (udg_yRegionsPerPlayer)) == 1 then
          call CreateNUnitsAtLoc( 1, 'hpea', ConvertedPlayer(IAbsBJ( i / udg_yPlayerCount)+1), GetRectCenter(udg_zRegion[i]), bj_UNIT_FACING )
      endif
    set i = i+1
  endloop   
  
  call TriggerSleepAction(1.5)
 set k = k+1
endloop
endfunction

//===========================================================================
function InitTrig_Spawn takes nothing returns nothing
    set gg_trg_Spawn = CreateTrigger(  )
    call TriggerRegisterTimerEventSingle( gg_trg_Spawn, 0.5 )
    call TriggerAddAction( gg_trg_Spawn, function Trig_Spawn_Actions )
endfunction
//===========================================================================

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 integer triggeringRectId = 0
  local unit triggeringUnit = GetTriggerUnit()


// ---function---
  //call DisplayTimedTextToForce(GetPlayersAll(),20, "Inside Actions ;)") 
  
  //Wait untill unit is really in - Bugs without, when entering from top...no clue why ;)
  call TriggerSleepAction(GetUnitMoveSpeed(triggeringUnit)/2000)

  //Get triggeringRectId
  set i = 1
  loop  
    exitwhen i>udg_zRegionCount
      if (RectContainsUnit(udg_zRegion[i],triggeringUnit)) then
        set triggeringRectId = i
      endif
    set i = i+1
  endloop
  
  //Show result
  call DisplayTimedTextToForce(GetPlayersAll(),20,"Entering udg_zRegion[" + I2S(triggeringRectId)+"]")
  
  //Its NOT the last point = next spawn moving!
  if ModuloInteger(triggeringRectId, (udg_yRegionsPerPlayer)) != 0 then  //All Numbers are x*y  (x=player no, y=playerwaypoints) 
    call IssuePointOrderLoc( triggeringUnit, "move", GetRectCenter(udg_zRegion[triggeringRectId+1]) )
    call DisplayTimedTextToForce(GetPlayersAll(),20,"Moving To: " + I2S(triggeringRectId+1)+" - caused by Mod: "+ I2S(ModuloInteger(triggeringRectId, (udg_yRegionsPerPlayer))))
    return 
  endif
  // Its the last point...so do whatever you want
  if ModuloInteger(triggeringRectId, (udg_yRegionsPerPlayer)) == 0 then
    call IssuePointOrderLoc( triggeringUnit, "move", GetRectCenter(udg_zRegion[(triggeringRectId-(udg_yRegionsPerPlayer-1))]) )
    call DisplayTimedTextToForce(GetPlayersAll(),20,"Moving To Start: " + I2S((triggeringRectId-(udg_yRegionsPerPlayer-1)))+" - caused by Mod: "+ I2S(ModuloInteger(triggeringRectId, (udg_yRegionsPerPlayer))))
     return 
  endif
    
//---clean up---
  set triggeringUnit = null
endfunction

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

  call SetRects()

  loop  // Register All Regions stored in the array
    exitwhen i>udg_zRegionCount 
      call TriggerRegisterEnterRectSimple(Movement, udg_zRegion[i])
    set i = i+1
  endloop

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



PS: Still have no good solution not to define the WP every event handling, so i can use the loop...don't wanna use vJass, even if some features are nice...

PPS: I really need that hide button...Which tag?
 

Attachments

  • runningtest.w3x
    22.2 KB · Views: 56
Last edited:
Level 3
Joined
Aug 20, 2008
Messages
54
First, you dont want to use the prefix udg in the globals because udg means the variables were made via trigger editor and not within the actual trigger. So remove all the "udg_".

You also want to, since in the last function, the init function, are using a local to create the trigger, which I always do, null the local at the end to remove leaks.

Also, you dont want to use TriggerSleepAction, it can cause a desync which disconnects a player or players. Use PolledWait(#.##) instead if you do not want to use a timer, though I suggest using timers.

And the answer to your question about them going to Center of Map? You said?
The center of map is when a point value (or location) gets nulled, the units will be sent to the location 0, 0 because the previous point's value was removed before the unit could take the order. This is probably being mainly caused by the TSA I mentioned earlier. Though PolledWait may not fix it, its a little more accurate than a TSA.

EDIT: Oh and just another optimization, you are using BJs, like CreateNUnitsAtLoc, dont use BJs, thats defeating half the purpose of switching from GUI. Well, maybe not half lol :)

EDIT 2: Use Hidden tags
 
Level 2
Joined
Feb 22, 2009
Messages
24
First: Thanks to the suggestion.. +rep

I only wrote the golobal in, so you can understand the Code...i also want that Variables to be Globals, as i want to use them in other functions too and dont want to end up with pseudo better ways, which uses up the 9% advantage of using locals when needing more speed to handle them.

I set the Wait to a polled wait...it works fine (20 minute run) when the delay is 0.3 Seconds... which is quite much! But i see no other way -.-*
 
Level 3
Joined
Aug 20, 2008
Messages
54
Thanks for Rep, but like I said, timers would be the way to go. Unlike TSAs they make a time which is exactly the same on every machine. TSAs can have a delay between machines which is what can easily cause the desyncs. Overall, timers are the best wait function to use for any kind of wait.

EDIT: If you are wondering how to change the BJs to natives, hold control and click the BJ (Only works in NewGen, red lettering) It will give you the native for what the BJ does, just copy and paste, then replace and customize.
 
Level 2
Joined
Feb 22, 2009
Messages
24
Using JassCraft...it shows me the function, so i look for the native directly...works good for me... Only used the Spawn-BJ, cause it was faster to convert, than to look in the doc...its just for testing purposes. When im going to make a huge project, i may switch to it, but for learning the facts behind the language full supporting systems only slows you.

Solved the problem wiht a range detection...not perfect, but it works without time using...
 
Status
Not open for further replies.
Top