Changes

Jump to navigation Jump to search
→‎Custom Actions: make C# examples collapse-able
Line 1,095: Line 1,095:     
===Custom Actions===
 
===Custom Actions===
C# mods can now handle custom <samp>Action</samp> & <samp>TouchAction</samp> [[Modding:Maps|map properties]] by calling <samp>GameLocation.RegisterTileAction</samp> & <samp>RegisterTouchAction</samp>, and passing a callback which receives the location, map property arguments, player who activated it, and tile position.
+
C# mods can handle custom <samp>Action</samp> & <samp>TouchAction</samp> map properties by calling <samp>GameLocation.RegisterTileAction</samp> & <samp>RegisterTouchAction</samp>, and passing a callback which receives the location, map property arguments, player who activated it, and tile position.
    
For example, let's say you want a locked gate which needs a custom key item. You can add a regular <code>TouchAction Example.ModId_UnlockGate</code> map property (e.g. by adding it directly in the map file, or using [[Modding:Content Patcher|Content Patcher]]'s <samp>EditMap</samp>, or using the [[Modding:Modder Guide/APIs/Content|content API]]). Then you can just handle the logic from your C# mod:
 
For example, let's say you want a locked gate which needs a custom key item. You can add a regular <code>TouchAction Example.ModId_UnlockGate</code> map property (e.g. by adding it directly in the map file, or using [[Modding:Content Patcher|Content Patcher]]'s <samp>EditMap</samp>, or using the [[Modding:Modder Guide/APIs/Content|content API]]). Then you can just handle the logic from your C# mod:
<syntaxhighlight lang="c#">
+
{{collapse|Example|content=<syntaxhighlight lang="c#">
 
internal class ModEntry : Mod
 
internal class ModEntry : Mod
 
{
 
{
Line 1,136: Line 1,136:  
     }
 
     }
 
}
 
}
</syntaxhighlight>
+
</syntaxhighlight>}}
    
As another example, let's say you want the gate to unlock when the player presses the action key. You can add a regular <code>Action Example.ModId_UnlockGate</code> map property (e.g. by adding it directly in the map file, or using [[Modding:Content Patcher|Content Patcher]]'s <samp>EditMap</samp>, or using the [[Modding:Modder Guide/APIs/Content|content API]]). Then you can just handle the logic from your C# mod:
 
As another example, let's say you want the gate to unlock when the player presses the action key. You can add a regular <code>Action Example.ModId_UnlockGate</code> map property (e.g. by adding it directly in the map file, or using [[Modding:Content Patcher|Content Patcher]]'s <samp>EditMap</samp>, or using the [[Modding:Modder Guide/APIs/Content|content API]]). Then you can just handle the logic from your C# mod:
<syntaxhighlight lang="c#">
+
{{collapse|Example|content=<syntaxhighlight lang="c#">
 
internal class ModEntry : Mod
 
internal class ModEntry : Mod
 
{
 
{
Line 1,179: Line 1,179:  
     }
 
     }
 
}
 
}
</syntaxhighlight>
+
</syntaxhighlight>}}
    
==Paths layer==
 
==Paths layer==
138

edits

Navigation menu