Modding/Templates/Instruction

From Desynced Wiki
Revision as of 12:33, 1 August 2023 by Bernhard (talk | contribs) (Created page with "__FORCETOC__ This mod template creates a new behavior instruction. == Code == === def.json === Content<syntaxhighlight lang="json"> { "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"...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

This mod template creates a new behavior instruction.

Code

def.json

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

Content

local package = ...

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

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

instructions.lua

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",
}