<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.pmdo.pmdcollab.org/wiki/index.php?action=history&amp;feed=atom&amp;title=Tutorial%3ABasic_Dungeon_Scripting</id>
	<title>Tutorial:Basic Dungeon Scripting - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.pmdo.pmdcollab.org/wiki/index.php?action=history&amp;feed=atom&amp;title=Tutorial%3ABasic_Dungeon_Scripting"/>
	<link rel="alternate" type="text/html" href="https://wiki.pmdo.pmdcollab.org/wiki/index.php?title=Tutorial:Basic_Dungeon_Scripting&amp;action=history"/>
	<updated>2026-07-31T15:16:20Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.44.0</generator>
	<entry>
		<id>https://wiki.pmdo.pmdcollab.org/wiki/index.php?title=Tutorial:Basic_Dungeon_Scripting&amp;diff=4730&amp;oldid=prev</id>
		<title>Imbion: Redirect due to redundancy (did I actually make this twice, ouch brain)</title>
		<link rel="alternate" type="text/html" href="https://wiki.pmdo.pmdcollab.org/wiki/index.php?title=Tutorial:Basic_Dungeon_Scripting&amp;diff=4730&amp;oldid=prev"/>
		<updated>2025-10-20T16:44:49Z</updated>

		<summary type="html">&lt;p&gt;Redirect due to redundancy (did I actually make this twice, ouch brain)&lt;/p&gt;
&lt;a href=&quot;https://wiki.pmdo.pmdcollab.org/wiki/index.php?title=Tutorial:Basic_Dungeon_Scripting&amp;amp;diff=4730&amp;amp;oldid=4724&quot;&gt;Show changes&lt;/a&gt;</summary>
		<author><name>Imbion</name></author>
	</entry>
	<entry>
		<id>https://wiki.pmdo.pmdcollab.org/wiki/index.php?title=Tutorial:Basic_Dungeon_Scripting&amp;diff=4724&amp;oldid=prev</id>
		<title>Imbion: Imbion moved page Basic Dungeon Scripting to Tutorial:Basic Dungeon Scripting</title>
		<link rel="alternate" type="text/html" href="https://wiki.pmdo.pmdcollab.org/wiki/index.php?title=Tutorial:Basic_Dungeon_Scripting&amp;diff=4724&amp;oldid=prev"/>
		<updated>2025-10-20T16:31:30Z</updated>

		<summary type="html">&lt;p&gt;Imbion moved page &lt;a href=&quot;/Basic_Dungeon_Scripting&quot; class=&quot;mw-redirect&quot; title=&quot;Basic Dungeon Scripting&quot;&gt;Basic Dungeon Scripting&lt;/a&gt; to &lt;a href=&quot;/Tutorial:Basic_Dungeon_Scripting&quot; class=&quot;mw-redirect&quot; title=&quot;Tutorial:Basic Dungeon Scripting&quot;&gt;Tutorial:Basic Dungeon Scripting&lt;/a&gt;&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 16:31, 20 October 2025&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-notice&quot; lang=&quot;en&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(No difference)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
		<author><name>Imbion</name></author>
	</entry>
	<entry>
		<id>https://wiki.pmdo.pmdcollab.org/wiki/index.php?title=Tutorial:Basic_Dungeon_Scripting&amp;diff=3972&amp;oldid=prev</id>
		<title>Imbion at 16:16, 22 August 2025</title>
		<link rel="alternate" type="text/html" href="https://wiki.pmdo.pmdcollab.org/wiki/index.php?title=Tutorial:Basic_Dungeon_Scripting&amp;diff=3972&amp;oldid=prev"/>
		<updated>2025-08-22T16:16:14Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 16:16, 22 August 2025&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l126&quot;&gt;Line 126:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 126:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;    end&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;    end&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;/pre&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;/pre&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;[[Category:Dungeon Generation]]&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;[[Category:Dungeon Generation&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;]][[Category:Scripting&lt;/ins&gt;]]&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Imbion</name></author>
	</entry>
	<entry>
		<id>https://wiki.pmdo.pmdcollab.org/wiki/index.php?title=Tutorial:Basic_Dungeon_Scripting&amp;diff=3970&amp;oldid=prev</id>
		<title>Imbion: Created page with &quot;This article is a guide on how to initalize the basic scripts for a zone (aka dungeon) script. Most of the complexity lies in the &lt;code&gt;ExitSegment&lt;/code&gt; function.  == About the File == When creating a zone, PMDO automatically creates a corresponding script file for the zone. These files can be found by going into the mod&#039;s root folder, and then following the path &lt;code&gt;Data/Script/[namespace]/zone&lt;/code&gt;. Then, to find the script file for a dungeon, select the folder w...&quot;</title>
		<link rel="alternate" type="text/html" href="https://wiki.pmdo.pmdcollab.org/wiki/index.php?title=Tutorial:Basic_Dungeon_Scripting&amp;diff=3970&amp;oldid=prev"/>
		<updated>2025-08-22T15:34:10Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;This article is a guide on how to initalize the basic scripts for a zone (aka dungeon) script. Most of the complexity lies in the &amp;lt;code&amp;gt;ExitSegment&amp;lt;/code&amp;gt; function.  == About the File == When creating a zone, PMDO automatically creates a corresponding script file for the zone. These files can be found by going into the mod&amp;#039;s root folder, and then following the path &amp;lt;code&amp;gt;Data/Script/[namespace]/zone&amp;lt;/code&amp;gt;. Then, to find the script file for a dungeon, select the folder w...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;This article is a guide on how to initalize the basic scripts for a zone (aka dungeon) script. Most of the complexity lies in the &amp;lt;code&amp;gt;ExitSegment&amp;lt;/code&amp;gt; function.&lt;br /&gt;
&lt;br /&gt;
== About the File ==&lt;br /&gt;
When creating a zone, PMDO automatically creates a corresponding script file for the zone. These files can be found by going into the mod&amp;#039;s root folder, and then following the path &amp;lt;code&amp;gt;Data/Script/[namespace]/zone&amp;lt;/code&amp;gt;. Then, to find the script file for a dungeon, select the folder with the corresponding name. Inside this will be a file called &amp;lt;code&amp;gt;init.lua&amp;lt;/code&amp;gt;, where all of the data for the zone is contained.&lt;br /&gt;
&lt;br /&gt;
There are four functions present in this file:&lt;br /&gt;
* &amp;lt;code&amp;gt;Init&amp;lt;/code&amp;gt;, which runs always when initializing the zone, aka whenever it is loaded&lt;br /&gt;
* &amp;lt;code&amp;gt;Rescued&amp;lt;/code&amp;gt;, which runs when being rescued by another team&lt;br /&gt;
* &amp;lt;code&amp;gt;EnterSegment&amp;lt;/code&amp;gt;, which runs when entering a segment&lt;br /&gt;
* &amp;lt;code&amp;gt;ExitSegment&amp;lt;/code&amp;gt;, which runs when exiting a segment&lt;br /&gt;
&lt;br /&gt;
All the functions are indexed into a table named after the zone&amp;#039;s internal name. For example, with a zone named &amp;lt;code&amp;gt;cave&amp;lt;/code&amp;gt;, the init function is defined as &amp;lt;code&amp;gt;cave.Init(zone)&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== Initializing ==&lt;br /&gt;
This gives the game instructions on what to do when initalizing the dungeon.&lt;br /&gt;
&lt;br /&gt;
Most zones do not require any unique steps to initialize them, unless custom scripting is implemented. Instead some debug lines are executed:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
DEBUG.EnableDbgCoro() --Enable debugging this coroutine&lt;br /&gt;
PrintInfo(&amp;quot;=&amp;gt;&amp;gt; Init_[zoneID]&amp;quot;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
These are just to make debugging easier in case something does go wrong with the scripting.&lt;br /&gt;
&lt;br /&gt;
== Rescues ==&lt;br /&gt;
This gives the game instructions on what to do when the player has been rescued.&lt;br /&gt;
&lt;br /&gt;
Rescues are simply handled with a single line in &amp;lt;code&amp;gt;Rescued&amp;lt;/code&amp;gt;:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
COMMON.Rescued(zone, name, mail)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This enables the game to execute the function that completes the rescue.&lt;br /&gt;
&lt;br /&gt;
== Entering a Segment ==&lt;br /&gt;
This gives the game instructions for what to do when entering a segment.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;EnterSegment&amp;lt;/code&amp;gt; typically has no extra scripting, other than cases where the player is rescuing another team:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  if rescuing ~= true then&lt;br /&gt;
    COMMON.BeginDungeon(zone.ID, segmentID, mapID)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Exiting Dungeon Segments ==&lt;br /&gt;
This gives the game instructions for what to do when exiting a segment. This is the primary function that requires scripting, because otherwise the game will simply stop execution and softlock if not given instructions.&lt;br /&gt;
&lt;br /&gt;
This function receives the following information when exiting a segment, storing them in variables:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;zone&amp;lt;/code&amp;gt;: The zone we currently exited.&lt;br /&gt;
* &amp;lt;code&amp;gt;result&amp;lt;/code&amp;gt;: The outcome of the dungeon exploration - Most relevant, this lets us check whenever the segment was cleared or if the player was defeated.&lt;br /&gt;
* &amp;lt;code&amp;gt;rescue&amp;lt;/code&amp;gt;: Tells us whenever we&amp;#039;re rescuing someone or not. This is true if we are rescuing, and false if we are not.&lt;br /&gt;
* &amp;lt;code&amp;gt;segmentID&amp;lt;/code&amp;gt;: A number that tells us what segment of the dungeon we&amp;#039;re exiting from, based on the ordering in the mod editor. It starts at 0 and counts up by one per next segment. &lt;br /&gt;
* &amp;lt;code&amp;gt;mapID&amp;lt;/code&amp;gt;: Says the map ID that we just exited from. Isn&amp;#039;t referenced most of the time. &lt;br /&gt;
&lt;br /&gt;
In order to tell the game what to do, we need to check if these variables have a certain value.&lt;br /&gt;
&lt;br /&gt;
=== An Example ===&lt;br /&gt;
&lt;br /&gt;
Let&amp;#039;s take a look at how the &amp;lt;code&amp;gt;ExitSegment&amp;lt;/code&amp;gt; function of &amp;#039;&amp;#039;Faded Trail&amp;#039;&amp;#039; works. We use a &amp;lt;code&amp;gt;if...elseif...else&amp;lt;/code&amp;gt; block in order to branch through our different choices.&lt;br /&gt;
&lt;br /&gt;
First, we want to check if we are in rescue mode, and succeeded on the rescue:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
local exited = COMMON.ExitDungeonMissionCheck(result, rescue, zone.ID, segmentID)&lt;br /&gt;
  if exited == true then&lt;br /&gt;
    --do nothing&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You only require this part of the block if your dungeon should support rescues.&lt;br /&gt;
&lt;br /&gt;
If exited is false, then we continue along the statement. This branch is taken if the dungeon was not cleared.:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  elseif result ~= RogueEssence.Data.GameProgress.ResultType.Cleared then&lt;br /&gt;
    COMMON.EndDungeonDay(result, SV.checkpoint.Zone, SV.checkpoint.Segment, SV.checkpoint.Map, SV.checkpoint.Entry)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The dungeon day is ended, and the player is sent back to their last checkpoint with punishments applied.&lt;br /&gt;
&lt;br /&gt;
If the above is false, then we enter into a branch that holds the results if we cleared the dungeon. So, all other results under this one else assume the player has cleared the dungeon.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;Faded Trail&amp;#039;&amp;#039; is a dungeon with an alternative dungeon segment that the player can take. We would like to do something different if the player clears the alternative segment. The default segment, &amp;#039;&amp;#039;Faded Trail&amp;#039;&amp;#039;, is segment 0, while the alternative segment, &amp;#039;&amp;#039;Hidden Trail&amp;#039;&amp;#039;, is segment 1.&lt;br /&gt;
&lt;br /&gt;
For segment 0, we just want to send the player to the forest camp:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    if segmentID == 0 then&lt;br /&gt;
      COMMON.EndDungeonDay(result, &amp;#039;guildmaster_island&amp;#039;, -1, 4, 0)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For segment 1, we want the player to go back to the island entrance and unlock a new dungeon:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    elseif segmentID == 1 then&lt;br /&gt;
      COMMON.UnlockWithFanfare(&amp;#039;faultline_ridge&amp;#039;, true)&lt;br /&gt;
      COMMON.EndDungeonDay(result, &amp;#039;guildmaster_island&amp;#039;, -1, 1, 3)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Finally, we make our last else be a fallback function that sends the player to their last checkpoint:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    else&lt;br /&gt;
      PrintInfo(&amp;quot;No exit procedure found!&amp;quot;)&lt;br /&gt;
	  COMMON.EndDungeonDay(result, SV.checkpoint.Zone, SV.checkpoint.Segment, SV.checkpoint.Map, SV.checkpoint.Entry)&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Blueprint ===&lt;br /&gt;
Putting it together, we get this psuedocode blueprint of what occurs while running &amp;lt;code&amp;gt;ExitSegment&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  --first check for rescue flag; if we&amp;#039;re in rescue mode then take a different path&lt;br /&gt;
  local exited = COMMON.ExitDungeonMissionCheck(result, rescue, zone.ID, segmentID) --check if we cleared while doing a rescue&lt;br /&gt;
  if exited == true then&lt;br /&gt;
        --do nothing; this is a dummy branch to stop us from going through the other branches&lt;br /&gt;
   elseif result ~= RogueEssence.Data.GameProgress.ResultType.Cleared then -- resolves true if the dungeon was not cleared&lt;br /&gt;
        --end the dungeon day by sending the player back to their last checkpoint, since they didn&amp;#039;t clear the dungeon&lt;br /&gt;
         COMMON.EndDungeonDay(result, SV.checkpoint.Zone, SV.checkpoint.Segment, SV.checkpoint.Map, SV.checkpoint.Entry)&lt;br /&gt;
   else -- we didn&amp;#039;t resolve true for being in rescue or losing the dungeon, so we must have cleared the dungeon&lt;br /&gt;
         -- now we will check what segment we took, so we can make the game do what we want to depending on the segment&lt;br /&gt;
         if segmentID == 0 then&lt;br /&gt;
            -- do things for exiting on segment 0&lt;br /&gt;
         elseif segmentID == 1 then&lt;br /&gt;
            -- do things for exiting on segment 1&lt;br /&gt;
         elseif .... -- continue checking likewise for all the segments we have&lt;br /&gt;
         else -- this is a fallback branch, in case we went through all of the branches and hit nothing (which should not happen!)&lt;br /&gt;
                 PrintInfo(&amp;quot;No exit procedure found!&amp;quot;)&lt;br /&gt;
                 -- just send the player to their last checkpoint&lt;br /&gt;
	             COMMON.EndDungeonDay(result, SV.checkpoint.Zone, SV.checkpoint.Segment, SV.checkpoint.Map, SV.checkpoint.Entry)&lt;br /&gt;
         end&lt;br /&gt;
   end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[Category:Dungeon Generation]]&lt;/div&gt;</summary>
		<author><name>Imbion</name></author>
	</entry>
</feed>