Skip to main content

Zone Actions

Zone Actions are similar to Event Actions but they're not automatically invoked in the same way as EventActions.

These are normally invoked by MessageTarget methods: the target for SendMessage.

Here's an example from TpSlideShow (edited for brevity):

protected void Access_ActionToTilePacket(ActionToTilePacket sentPacket)                                                                                                           
{                                                                                                                                                                                 
    if (sentPacket.SourceInstance == this)                                                                                                                                        
        return; //avoid recursion.                                                                                                                                                
    if (!m_AcceptsClicks)                                                                                                                                                         
        return;                                                                                                                                                                   
    if (sentPacket.Delay != 0)                                                                                                                                                    
    {                                                                                                                                                                                                  
        TpLib.DelayedCallback(this,()=>ChangeSlide(SlideIndex == 0,false,false),"DelayATTP_Slideshow", sentPacket.Delay);                                                         
        if(m_ZoneAction)                                                                                                                                                          
            m_ZoneAction.Exec(this, this.GetType(), m_ZoneTargetTag, ObjectPacket.EventsPropagationMode.ZoneEvents,"",SlideIndex);                                                
                                                                                                                                                                                  
    }                                                                                                                                                                             
    else                                                                                                                                                                          
        ChangeSlide(slideIndex == 0, true,sentPacket.PostEvent);                                                                                                                  
}              

So this MessageTarget is a recipient of Messages from TpActionToTile which is the S.O. that converts clicks to tile positions. Having found one, it sends this message and (if there's a delay) invoked the ZoneActions's Exec method.

The Exec method declaration:

public virtual bool Exec(TilePlusBase                       sourceInstance,                                                  
                         Type?                              targetType,                                                      
                         string                             tagString,                                                       
                         ObjectPacket.EventsPropagationMode eventPropagationMode = ObjectPacket.EventsPropagationMode.None,  
                         string                             optionalString       = "",                                       
                         int                                optionalInt          = 0,                                        
                         bool                               optionalBool         = false,                                    
                         object?                            optionalObject       = null)                                     

As you can see, the parameters have some specific information like:

  • targetType (here passed-in as the Type of the invoking TPT tile)
  • tagString (here passed-in as a specific value from the invoking TPT tile)

and some general parameters:

  • optionalString
  • optionalInt
  • optionalBool
  • optionalObject

These can be whatever you want. In this example, optionalInt is used to pass the current SlideIndex which specfies which sprite is being displayed.

It's probably obvious that the invoking tile has to know a what the ZoneActions needs and the ZoneAction has to be designed for a specific purpose: there's an unavoidable dependency.