<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="fr">
	<id>https://www.lets-role.wiki/index.php?action=history&amp;feed=atom&amp;title=Init_Advanced_Tip</id>
	<title>Init Advanced Tip - Historique des versions</title>
	<link rel="self" type="application/atom+xml" href="https://www.lets-role.wiki/index.php?action=history&amp;feed=atom&amp;title=Init_Advanced_Tip"/>
	<link rel="alternate" type="text/html" href="https://www.lets-role.wiki/index.php?title=Init_Advanced_Tip&amp;action=history"/>
	<updated>2026-05-25T06:18:00Z</updated>
	<subtitle>Historique des versions pour cette page sur le wiki</subtitle>
	<generator>MediaWiki 1.42.1</generator>
	<entry>
		<id>https://www.lets-role.wiki/index.php?title=Init_Advanced_Tip&amp;diff=37&amp;oldid=prev</id>
		<title>Guile : Page créée avec « As soon as you have a large number of different sheet to initialize (more than 10), we recommend to use more advanced code to make it shorter. It uses a list of initializers associated with the sheet id. This will prevent you to write a large and repetitive list of &lt;code&gt;if else if&lt;/code&gt;. The following code shows one way to do it.  // A list of initializers, associating the sheet id with an init function  const initializers = {      main: initMain,      monster:... »</title>
		<link rel="alternate" type="text/html" href="https://www.lets-role.wiki/index.php?title=Init_Advanced_Tip&amp;diff=37&amp;oldid=prev"/>
		<updated>2025-09-01T14:58:10Z</updated>

		<summary type="html">&lt;p&gt;Page créée avec « As soon as you have a large number of different sheet to initialize (more than 10), we recommend to use more advanced code to make it shorter. It uses a list of initializers associated with the sheet id. This will prevent you to write a large and repetitive list of &amp;lt;code&amp;gt;if else if&amp;lt;/code&amp;gt;. The following code shows one way to do it.  // A list of initializers, associating the sheet id with an init function  const initializers = {      main: initMain,      monster:... »&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Nouvelle page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;As soon as you have a large number of different sheet to initialize (more than 10), we recommend to use more advanced code to make it shorter. It uses a list of initializers associated with the sheet id. This will prevent you to write a large and repetitive list of &amp;lt;code&amp;gt;if else if&amp;lt;/code&amp;gt;. The following code shows one way to do it.&lt;br /&gt;
 // A list of initializers, associating the sheet id with an init function&lt;br /&gt;
 const initializers = {&lt;br /&gt;
     main: initMain,&lt;br /&gt;
     monster: initMonster,&lt;br /&gt;
     object: initObject,&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 init = function (sheet) {&lt;br /&gt;
     const sheetId = sheet.id()&lt;br /&gt;
     if (initializers[sheetId]) {&lt;br /&gt;
         initializers[sheetId](sheet);  // this line will execute the desired initializer.&lt;br /&gt;
     }&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 function initMain(sheet) {&lt;br /&gt;
     // write you code here for the sheet with the id &amp;quot;main&amp;quot;&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 function initMonster(sheet) {&lt;br /&gt;
     // write you code here for the sheet with the id &amp;quot;monster&amp;quot;&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 function initObject(sheet) {&lt;br /&gt;
     // write you code here for the sheet with the id &amp;quot;object&amp;quot;&lt;br /&gt;
 }&lt;br /&gt;
One big pro for this technic is that the init function will not change anymore. If you want to add a new sheet to initialize (e.g., &amp;lt;code&amp;gt;vehicule&amp;lt;/code&amp;gt;), you have to create a new function called &amp;lt;code&amp;gt;initVehicule&amp;lt;/code&amp;gt; and reference if in &amp;lt;code&amp;gt;initializers&amp;lt;/code&amp;gt; (adding a line &amp;lt;code&amp;gt;vehicule: initVehicule&amp;lt;/code&amp;gt;).&lt;/div&gt;</summary>
		<author><name>Guile</name></author>
	</entry>
</feed>