Sorry, we don't support your browser.  Install a modern browser

event onObjectEnterZone() triggers before onObjectLeaveZone()#3024

J

When you have two FogOfWarTriggers (‘hidden zones’) right next to each other (but not overlapping), if they have both have code such as:

function onObjectEnterZone(zone, object)
if zone.getGUID() == self.getGUID() then
doSomethingHere
end
end

function onObjectLeaveZone(zone, object)
if zone.getGUID() == self.getGUID() then
doSomethingElseHere
end
end

and you drag a object from Zone1 to Zone2, the triggers are in this order:

  • Object has entered Zone2
  • Object has left Zone1

This can be reliably seen with similar/mirrored code in both event handlers, such as:
function onObjectLeaveZone(zone, object)
if zone.getGUID() == self.getGUID() then
zoneHidden = Global.getVar(“AAA”)
print(“Object has left zone “ .. zone.getGUID() ..”, hidden “ .. tostring(zoneHidden))
object.setInvisibleTo({})
end
end

3 months ago

When you have two FogOfWarTriggers (‘hidden zones’) right next to each other (but not overlapping)

as in, just barely not touching? if so, then the object is actually entering one before leaving the other, as the condition for whether an object is within a trigger is based off whether object’s collider intersects the trigger, rather than its position

3 months ago
J

The gap is about 1/4th the size of a piece, so I would say the zones are just barely not touching. yes. A possible mitigation would be to make the gap wider then?

The situation I am trying to make is from the boardgame Red Storm Rising:
The table has 2 teams, a central play area, and each team has an area for units/pieces in reserve that is opposite of the central play area, and each team has a prep area at the same side of the table next to the central play area.
The reserve area is to be hidden at all times for the other team. The prep area starts hidden to the other team. In a certain phase they have to “secretly” move objects to the prep area and then temporarily reveal what they have prepped, do stuff, and then move them onto the always-revealed central board. Once this is done, the prep area needs to be hidden again to the other team. There will still be (static and known) objects in the prep area throughout all of this.

Currently, I am solving it like this:
The reserve and prep area each have a hidden zone. set to reserve hide on White (no player has that colour). The central area does not have any hidden zones. If a object enters a hidden zone, each zone checks a global var whether the prep zone should be hidden, then hides it appropriately or not. Similarly, if it leaves a zone it unhides it for everyone (assuming it goes to the central area).
The issue I am having with this is that if we move objects from reserve to prep area, other teams can see it as mentioned, it hides (‘enters’) before it reveals it (‘leaves’). Other than that, the set-up works.

Any recommendations to get the intended behaviour?
Thanks for answering so quickly btw!

3 months ago