Modding/Templates/Instruction

From Desynced Wiki

This mod template creates a new behavior instruction.

Code[edit | edit source]

def.json[edit | edit source]

Content

{
    "id": "ModTemplateInstruction",
    "name": "Mod Template Instruction",
    "version_name": "1.0",
    "version_code": 1,
    "author": "The Desynced Team",
    "homepage": "https://www.desyncedgame.com/",
    "description": "Mod Template Instruction",
    "packages": {
        "Data": {
            "name": "Data",
            "entry": "data.lua",
            "dependencies": [ "Main/Data" ],
            "type": "Addon"
        }
    }
}

data.lua[edit | edit source]

Content

local package = ...

-- files loaded when mod is initializing
package.includes = {
	"instructions.lua",
}

-- called when mod is initializing
function package:init()
end

instructions.lua[edit | edit source]

Content

-- Local references for shorter names and avoiding global lookup on every use
local Get, GetNum, GetId, GetEntity, AreEqual, Set = InstGet, InstGetNum, InstGetId, InstGetEntity, InstAreEqual, InstSet

data.instructions.mod_add_one =
{
	func = function(comp, state, cause, from, to)
		local r = Tool.NewRegisterObject(Get(comp, state, from)) -- copy to avoid changing from
		r.num = r.num + 1
		Set(comp, state, to, r)
	end,
	args = {
		{ "in", "From", nil, "num" },
		{ "out", "To" },
	},
	name = "Add One [MOD]",
	desc = "Adds one to a number",
	category = "Math",
	icon = "Main/skin/Icons/Special/Commands/Add Numbers.png",
}