LenchScripterMod icon indicating copy to clipboard operation
LenchScripterMod copied to clipboard

How to control my mod

Open Tonmyn opened this issue 7 years ago • 1 comments

I write a MOD for the SuspensionBlock. MOD add a slider to SuspensionBlock,Now I want control slider value use ScriptMod. What should I do?

Tonmyn avatar Aug 16 '17 07:08 Tonmyn

You can link LenchScripterMod.dll to your mod, and then create a class named SuspensionBlockHandler that extends Lench.Scripter.Block, like this:

namespace MyMod
{
    public class SuspensionBlockHandler : Lench.Scripter.Block
    {
        private readonly SuspensionBlock _sb;

        public SuspensionBlockHandler(BlockBehaviour bb) : base(bb)
        {
            _sb = bb.GetComponent<SuspensionBlock>();
        }

        public void DoSomething()
        {
            _sb.CallSomeMethodFromYourBlockScript();
        }
    }
}

Then on mod load, call

Lench.Scripter.MapTypeToID(myBlockId, typeof(SuspensionBlockHandler));

where myBlockId is the integer ID of your block. This will tell the scripter mod to create block handlers of your type for blocks with given ID number.

Users will then be able to access your methods in Python.

b = Besiege.GetBlock("SUSPENSION BLOCK 1")
b.DoSomething()

Linking the scripter mod library will unfortunately cause your mod to stop working when scripter mod is not present. That's why I suggest creating a scripter and scripterless version of mod, or creating a scripter plugin that does just this.

lenartbezek avatar Aug 16 '17 10:08 lenartbezek