

“Pure” in this context means that the functions could run outside of Minetest - none of the engine’s functions are called. You should write your data representation using Pure Lua.

#Minetest car mod code#
You won’t need to test that an event calls an action (as this would require using the Minetest API, and this area of code should be made as small as possible anyway.) In your tests, you will be able to make sure that an action when triggered does the right thing to the data.
.png)
These are 3 areas that can usually be separated pretty well. The events that trigger these actions are chat commands and formspec receive fields. Actions you can take are create, edit, or delete. The data you have is the areas and any associated metadata. Let’s take an example of a land protection mod.
#Minetest car mod how to#
In the next chapter, we will discuss how to automatically test your code and one of the problems we will have is how to separate your logic (calculations, what should be done) from API calls ( minetest.*, other mods) as much as possible. And you’re right! The Minetest API is heavily Observer-based to stop the engine having to care about what is listening to something. You may be thinking - wait a second, this looks awfully familiar. register_on_death ( function ( mob, reason ) if reason.
#Minetest car mod mod#
Instead of the mymobs mod caring about awards, the mymobs mod exposes a way for other areas of code to register their interest in an event and receive data about the event.

If you kept on doing this - for example, adding XP to the mob death code - you could end up with a lot of messy dependencies.Įnter the Observer pattern. This is a bad idea, however, as it makes the mobs mod coupled to the achievements code. The naïve approach would be to have achievement code in the mob kill function, checking the mob name and unlocking the award if it matches. Let’s take the example of unlocking an achievement when a player first kills a rare animal. ObserverĪ simple way to separate different areas of code is to use the Observer pattern. Note that these apply both when thinking about the relationship between mods, and the relationship between areas inside a mod. It’s a very good idea to make sure you have a low amount of coupling, as this means that changing the APIs of certain areas will be more feasible. Low Coupling - keep dependencies between areas as low as possible, and avoid relying on internal implementations.High Cohesion - the area should be closely/tightly related.These programs/areas should have the following two properties: This should be done in such a way that you achieve Separation of Concerns - each area should be distinct and address a separate need or concern. Inside every large program, there is a small program trying to get out. The opposite of this is to design your project as a collection of interacting smaller programs or areas of code. This ultimately makes a project completely unmaintainable, ending in its abandonment. Spaghetti code is characterised by a lack of structure - all the code is thrown in together with no clear boundaries. Without any planning, a programming project will tend to gradually descend into spaghetti code. Cohesion, Coupling, and Separation of ConcernsĬohesion, Coupling, and Separation of Concerns.There is no one good way of designing a mod, and good mod design is very subjective. Please note that this chapter isn’t meant to be prescriptive, but to instead give you an idea of the possibilities. This chapter covers important concepts needed to keep your code clean, and common design patterns to achieve that. This is an especially big problem when using a dynamically typed language like Lua, given that the compiler gives you very little compiler-time help when it comes to things like making sure that types are used correctly.
#Minetest car mod free#
Once your mod reaches a respectable size, you’ll find it harder and harder to keep the code clean and free of bugs. En Intro to Clean Architectures Introduction
