<?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%3AMod_Script_File_Management</id>
	<title>Tutorial:Mod Script File Management - 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%3AMod_Script_File_Management"/>
	<link rel="alternate" type="text/html" href="https://wiki.pmdo.pmdcollab.org/wiki/index.php?title=Tutorial:Mod_Script_File_Management&amp;action=history"/>
	<updated>2026-07-31T06:51:30Z</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:Mod_Script_File_Management&amp;diff=4818&amp;oldid=prev</id>
		<title>Imbion: Created page with &quot;In programming, keeping the majority of code in the same area is generally viewed as a bad practice. It can reduce the efficiency of moving through files, results in a project being harder to read, and overall makes the coding experience more difficult.  In PMDO Modding, the primary area this problem appears when creating lua scripts for ground maps. Figuring out a method to manage ground map files is important.  == Accessing Different Script Files == The core enabler of...&quot;</title>
		<link rel="alternate" type="text/html" href="https://wiki.pmdo.pmdcollab.org/wiki/index.php?title=Tutorial:Mod_Script_File_Management&amp;diff=4818&amp;oldid=prev"/>
		<updated>2025-10-24T18:19:19Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;In programming, keeping the majority of code in the same area is generally viewed as a bad practice. It can reduce the efficiency of moving through files, results in a project being harder to read, and overall makes the coding experience more difficult.  In PMDO Modding, the primary area this problem appears when creating lua scripts for ground maps. Figuring out a method to manage ground map files is important.  == Accessing Different Script Files == The core enabler of...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;In programming, keeping the majority of code in the same area is generally viewed as a bad practice. It can reduce the efficiency of moving through files, results in a project being harder to read, and overall makes the coding experience more difficult.&lt;br /&gt;
&lt;br /&gt;
In PMDO Modding, the primary area this problem appears when creating lua scripts for ground maps. Figuring out a method to manage ground map files is important.&lt;br /&gt;
&lt;br /&gt;
== Accessing Different Script Files ==&lt;br /&gt;
The core enabler of file organization is the ability to reference the contents of different files in lua.&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;require&amp;lt;/code&amp;gt; keyword may be used to access files by specifying where they can found. This keyword starts relative to PMDO&amp;#039;s base &amp;lt;code&amp;gt;script&amp;lt;/code&amp;gt; folder - and, in the case of a mod, that mod&amp;#039;s based &amp;lt;code&amp;gt;script&amp;lt;/code&amp;gt; folder.&lt;br /&gt;
&lt;br /&gt;
Using the require keyword makes all of the global variables (variables not defined prefixed by &amp;lt;code&amp;gt;local&amp;lt;/code&amp;gt;) found in the other file accessible by the file that called that keyword. Because functions in Lua are stored by writting them to a table to be called later, we can reference a global table and any of its functions. So, with all functions defined to a global table, that table is now able to have all of its functions called from a foreign file.&lt;br /&gt;
&lt;br /&gt;
Scripts that are added specifically by a mod should be placed in the subfolder of scripts named after that mod&amp;#039;s namespace. For example, a mod with the namespace of &amp;lt;code&amp;gt;test_mod&amp;lt;/code&amp;gt; should have all of its implemented scripts put into that folder. This is to avoid collision with the names of other mod&amp;#039;s files.&lt;br /&gt;
&lt;br /&gt;
=== Example ===&lt;br /&gt;
Suppose we have the file &amp;lt;code&amp;gt;code.lua&amp;lt;/code&amp;gt; placed within the &amp;lt;code&amp;gt;test_mod&amp;lt;/code&amp;gt; folder with the contents:&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;Code = {}&lt;br /&gt;
&lt;br /&gt;
function Code.go()&lt;br /&gt;
      -- imagine this function does something&lt;br /&gt;
end&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Say we have some other script file that we want to call the function &amp;lt;code&amp;gt;Code.go()&amp;lt;/code&amp;gt;, which is present inside of &amp;lt;code&amp;gt;code.lua&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
It is possible to do so by writting this in that file:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;require &amp;#039;test_mod.code&amp;#039;&lt;br /&gt;
&lt;br /&gt;
Code.go()&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When that file is loaded, the &amp;lt;/code&amp;gt;Code.go()&amp;lt;/code&amp;gt; function will be immediately called.&lt;br /&gt;
&lt;br /&gt;
== Structuring Ground Script Files ==&lt;br /&gt;
A common area that must be organized and structured in mods is the script files for ground maps. These often require tons of scripting for things such as cutscenes, ground NPC dialogue, shop access, and checking state. For most modders, splitting the ground script folder up into different subfolders is the most useful.&lt;br /&gt;
&lt;br /&gt;
There are two different primary file structures that have been found to be useful.&lt;br /&gt;
&lt;br /&gt;
=== Section Splitting ===&lt;br /&gt;
Ground map scripts are split on &amp;quot;chapters&amp;quot;, or what current section of the story the player will be in when they can encounter those scripts. &lt;br /&gt;
&lt;br /&gt;
This is typically done when a mod is designed on a chapter-to-chapter basis, and will have new chapters gradually added to it over time. This naturally splits the code into the parts of each chapter, which will be worked on simultaneously.&lt;br /&gt;
&lt;br /&gt;
=== Purpose Splitting ===&lt;br /&gt;
Ground map scripts are split depending on the purpose that each piece of code serves. This is useful for developers who prefer to work on different sections of the code rather than directly on story sections.&lt;br /&gt;
&lt;br /&gt;
One schema for splitting the files:&lt;br /&gt;
* &amp;lt;code&amp;gt;init.lua&amp;lt;/code&amp;gt; - The primary driver and manager of being on the ground map. This mostly calls all of the functions as they are needed, and does activities such as checking for state.&lt;br /&gt;
* Interacts - The interactions from talking to NPCS on the map. These functions are directly called in each of the base action functions, and are passed the activator and activated character.&lt;br /&gt;
* Cutscenes - Cutscenes that will be played as needed. Often can be passed characters and other variables from the init.&lt;br /&gt;
* State - Manages the visible state of the ground map.&lt;br /&gt;
&lt;br /&gt;
[[Category:Tutorial]]&lt;/div&gt;</summary>
		<author><name>Imbion</name></author>
	</entry>
</feed>