• 🏆 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!
  • ✅ HD Level Design Contest #1 POLL is now OPEN! Check out the stunning visuals of the final entries. 🔗Click here to cast your vote!

Maze trigger problem

Status
Not open for further replies.
Level 13
Joined
Mar 24, 2013
Messages
1,105
I'm having some difficulty here, it will result in a crash when I test it and spam units, if their is 1 to 10, it works without a problem but should it have to a mass amount like 30 or so it leads to a crash, and I'm not entirely sure what the problem is...

I'm sure it must be hitting some kind of infinite loop or something causing it but I am not seeing it.

Any help would be great

  • TD Region Setup
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Set TDRegions[1] = TDspawn1 <gen>
      • Set TDRegions[2] = TDspawn2 <gen>
      • Set TDRegions[3] = TDspawn3 <gen>
      • Set TDRegions[4] = TDspawn4 <gen>
      • Set TDRegions[5] = TDspawn5 <gen>
      • Set TDRegions[5] = TDspawn5 <gen>
      • Set TDRegions[6] = TDspawn6 <gen>
      • Set TDRegions[7] = TDspawn7 <gen>
      • Set TDRegions[8] = TDspawn8 <gen>
      • Set TDRegions[9] = TDa1 <gen>
      • Set TDRegions[10] = TDa2 <gen>
      • Set TDRegions[11] = TDa3 <gen>
      • Set TDRegions[12] = TDa4 <gen>
      • Set TDRegions[13] = TDa5 <gen>
      • Set TDRegions[14] = TDa6 <gen>
      • Set TDRegions[15] = TDa7 <gen>
      • Set TDRegions[16] = TDa8 <gen>
      • Set TDRegions[17] = TDb1 <gen>
      • Set TDRegions[18] = TDb2 <gen>
      • Set TDRegions[19] = TDb3 <gen>
      • Set TDRegions[20] = TDb4 <gen>
      • Set TDRegions[21] = TDb5 <gen>
      • Set TDRegions[22] = TDb6 <gen>
      • Set TDRegions[23] = TDb7 <gen>
      • Set TDRegions[24] = TDb8 <gen>
      • Set TDRegions[25] = TDc1 <gen>
      • Set TDRegions[26] = TDc2 <gen>
      • Set TDRegions[27] = TDc3 <gen>
      • Set TDRegions[28] = TDc4 <gen>
      • Set TDRegions[29] = TDc5 <gen>
      • Set TDRegions[30] = TDc6 <gen>
      • Set TDRegions[31] = TDc7 <gen>
      • Set TDRegions[32] = TDc8 <gen>
      • For each (Integer TempInteger) from 1 to 32, do (Actions)
        • Loop - Actions
          • Trigger - Add to TD Movement <gen> the event (Unit - A unit enters TDRegions[TempInteger])
  • TD Movement
    • Events
    • Conditions
    • Actions
      • Set TempUnit = (Triggering unit)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • ((Owner of TempUnit) controller) Not equal to User
        • Then - Actions
          • For each (Integer TempInteger2) from 1 to 32, do (Actions)
            • Loop - Actions
              • Custom script: if IsUnitInRect(udg_TDRegions[udg_TempInteger2], udg_TempUnit) == true then
              • Set TempInteger = TempInteger2
              • Custom script: endif
          • Unit - Set level of Region Tracker for TempUnit to ((Level of Region Tracker for TempUnit) + 1)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Level of Region Tracker for TempUnit) Equal to 6
            • Then - Actions
              • Set TempPlayer = (Player(TempInteger))
              • Set TempForce = (All allies of TempPlayer)
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • TempInteger Less than or equal to 4
                • Then - Actions
                  • Set Lives[2] = (Lives[2] + 1)
                  • Set TempInteger2 = 2
                • Else - Actions
                  • Set Lives[1] = (Lives[1] + 1)
                  • Set TempInteger2 = 1
              • Game - Display to (All players) the text: (playerColors[1] + (((Name of TempPlayer) + is leaking lives to the other team! ) + ( They now have + ((String(Lives[TempInteger2])) + lives!))))
              • -------- END --------
              • Unit - Set level of Region Tracker for TempUnit to 2
              • Set TempPoint = (Center of TDRegions[(TempInteger + 8)])
              • Unit - Order TempUnit to Patrol To TempPoint
              • Custom script: call RemoveLocation(udg_TempPoint)
            • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Level of Region Tracker for TempUnit) Equal to 5
                • Then - Actions
                  • Set TempPoint = (Center of TDRegions[(TempInteger - 24)])
                • Else - Actions
                  • Set TempPoint = (Center of TDRegions[(TempInteger + 8)])
          • Unit - Order TempUnit to Patrol To TempPoint
          • Custom script: call RemoveLocation(udg_TempPoint)
        • Else - Actions
JASS:
function IsUnitInRect takes rect whichRect, unit whichUnit returns boolean
    local region r = CreateRegion()
    local boolean inside

    call RegionAddRect(r, whichRect)
    set inside = IsUnitInRegion(r, whichUnit)
    call RemoveRegion(r)
    set r = null

    return inside
endfunction

edit: Here's the function shown in the 2nd trigger. It's not mine, I think it might be PnF's actually :p
 
Last edited:
  • Set TempPlayer = (Player(TempInteger))
^Why this? The integer is between 1 and 32. So there can be a invalid player. -> probably crash.

  • Set TempPoint = (Center of TDRegions[(TempInteger + 8)])
^Why this? You might access to Region[33-41], which do not exist.

Also your other operations with CentreOfRegion[Integer + <number>] doesn't seem to make sense.

Btw, to check if a unit is inside a rect you simply can do this:
JASS:
function IsUnitInRect takes unit u, rect r returns boolean
    local real x = GetUnitX(u)
    local real y = GetUnitY(u)
    return (GetRectMinX(r) <= x) and (x <= GetRectMaxX(r)) and (GetRectMinY(r) <= y) and (y <= GetRectMaxY(r))
endfunction
 
Level 13
Joined
Mar 24, 2013
Messages
1,105
Thanks for the reply!

I do see what you mean, I guess I need to make another check for when I get the ability equal to 6 and be sure the number isn't larger than 15 to avoid the crash that way, although it technically should only reach level 6/fire when it enters the regions that are from 1 to 8 but if it fouls up it could.

Let me explain because maybe you know a better way to achieve what I want xD.

So my creeps spawn with an ability denoted here as "Region Tracker", I increase the level every time it enters the region. They go in a square so when they first begin they will start with it level 2 (they have the ability and then it just gets +1), then when they reach the next region, the ability is level 3, etc, all the way around. When it reenters the starting corner of the square it will now it be level 6 so I can now do things since they leaked the creep.

The reasoning for having TDRegions[TempInteger + 8] is because unless its the final leg of the square, the regions for player 1 for example are, 1,9,17,25. And when it reaches the point where it needs to go back to the 1st set I check what level the tracking ability is, it should be lvl 5 so I set the point to TDRegions[TempInteger -24] which would take player's back to the starting/ending location.
Now that I think about, I guess I could just go up to 40 and repeat the initial regions and not have to worry about checking and could just +8 again...

But is there a smarter way to do this? Am I over complicating it?

I will change and use that function to check!

Hope I am being clear! Thanks again.

edit: The reason the crash occurs is because the Player value was becoming something too large such as Player(23), but this was only occurring because when the units are going through the regions when its in mass quantities they bump into each other pushing them around and causing them to reenter the region they just came from multiple times causing them to reach level 6 too soon, which caused the If to try and evaluate for the wrong region which so happened to be an invalid player index leading to a game crash. That was a long winded way of saying, is there a better way to avoid them to being pushed in and out of the region? Might it be better to give them a different ability for each region rather than increasing it for each region entered?
 
Last edited:
You only need the ability to bind an integer to the unit? You can directly store the "region track id" into interer[array] (with help of a unit indexer for example), or save the value into hashtable. (with help of specific HandleId of each unit as parent key)

And when a unit enters a region, first compare the current "region track id" of the unit, to know if the actions should run, or not.
 
Status
Not open for further replies.
Top