User blog:Imamadmad/Changes to Template:Difficulty level

As I announced earlier, changes are coming to the back end of Difficulty level which will make is work a lot faster and demand far fewer resources on the page. This change is going to take place not long after I post this blog, so you can refer to it when it is needed to make changes.

Usage
Difficulty level will be implemented exactly the same as before when using the template on a page. For those of you who use source mode (which I expect is far fewer than I think), simply writing Difficulty level on a page will bring up its difficulty and writing Level ### will provide the difficulty for Level ###, just as before. However, a couple of extra features have been added for our convenience. Now, if you write Level ###, you'll be presented with just the Facebook difficulty level, and if you write Level ###, you'll be presented with just the mobile difficulty. If the medium of the split difficulty level isn't set, it will display as it did previously in the relevant templates.

Those of you who use the VisualEditor should probably stop and use source mode from the classic editor instead because it is infinitely better, but until I can convince you of that, you should be able to add the template normally through the template adder thing, with the difficulty level of the current page being shown if there are no parameters, the difficulty of the stated level showing if the first parameter is used, and it should have a second parameter in which you can write either "Facebook" or "Mobile" to get the specific difficulty of the level stated in parameter one.

Changing of difficulties
Now, while there is little difference to the regular user when it comes to adding the template to a page, there is a huge difference to how the difficulty levels are updated within the template, or should I say template and modules.

To start with, Difficulty level is not the entire template any more. In fact, it is little more than an easy way to call the modules which make up the main data structures of the template. There is also Module:Difficulty level, Module:Difficulty level/Reality, and Module:Difficulty level/Dreamworld. Now, unless you are experienced in Lua and have a good reason for doing so, please do not edit Module:Difficulty level. That is where all the commands in the template reside, which take in the information and then figure out what to do with it. The modules where the information which can be changed resides is in Module:Difficulty level/Reality and Module:Difficulty level/Dreamworld, for the reality and Dreamworld levels respectively.

To see how to update this information, let me first pull the section from the first episode of reality from the module.

return { -- Candy Town [1] = 'Very Easy', [2] = 'Very Easy', [3] = 'Very Easy', [4] = 'Very Easy', [5] = 'Very Easy', [6] = 'Very Easy', [7] = 'Very Easy', [8] = 'Very Easy', [9] = 'Very Easy', [10] = 'Very Easy', }

Leave the return part alone, along with the {curly braces} which start and finish the page, as those are what send all the data on that page to Module:Difficulty level to be processed. Now, the numbers inside the [square brackets] are the numbers of the level, and the values (better known to programmers as strings) inside the 'quotes' are the difficulty level of the level number beside it. If you want to change the difficulty level, simply change the word within the quotes to the name of the new difficulty. The double dash (--) is there to indicate the beginning of a comment in the code, a comment being a string of text or whatever which is ignored by the code when run but can make the lives of coders easier. Here it is being used to denote the episode name of the levels beneath it, but a double dash can be used anywhere in the code if a comment is needed to be made elsewhere, even to the right of another lot of code which is included.

Let me now pull out another sample of code for your viewing. -- Aurora Chocorealis [36] = 'Very Easy', [37] = 'Considerably Easy', [38] = 'Easy', [39] = 'Easy', [40] = 'Considerably Hard', [41] = 'Considerably Easy', [42] = 'Easy', [43] = {'Medium','Very Hard'}, [44] = 'Easy', [45] = 'Medium', [46] = 'Considerably Easy', [47] = 'Hard', [48] = 'Medium', [49] = 'Easy', [50] = 'Very Easy', This is from the Dreamworld module, and as you can see, the numbers are listed identically to how they are in the reality module. In fact, in most ways, this and the previous section are identical in function. There is one major difference though, and that is concerning split difficulty Level 43/Dreamworld. Instead of having the clunky piece of code with the difficulties split as they would be on the page, they are instead added as an array (I think that's the term for it. I haven't studied Lua much personally). The first term in the array is the Facebook difficulty while the second is the Mobile difficulty, formatted as you see above with the {curly braces}, 'quotes' around each difficulty, and a comma separating the two difficulties. That is how all split difficulties are formatted in this new module structure, in both the Dreamworld and Reality modules.

That should be all you need to know to use and update Difficulty level as you have in the past. If you have any problems or questions, please feel free to contact me on my message wall.

I would like to thank TJcool007 for writing the Lua code needed to update this template. Without his help, Difficulty level could never have been improved to such and extent with such seamless integration into the previous usage of the template.