Quantcast
Channel: ClearScript
Viewing all articles
Browse latest Browse all 2297

New Post: Using methods in a script

0
0
Hello, Fraysa!

There are many ways to do this. Here's one possibility:
publicabstractclass ScriptBase {
    protected ScriptEngine _engine { get; privateset; }
    privatestring _code;
    publicvirtualvoid Run() {
        _engine.Execute(_code);
    }
    /* ... */
}
publicclass NpcScript : ScriptBase {
    privatevoid SendNext(string text) { /* ... */ }
    privatevoid SendYesNo(string text) { /* ... */ }
    publicoverridevoid Run() {
        _engine.Script.SendNext = new Action<string>(SendNext);
        _engine.Script.SendYesNo = new Action<string>(SendYesNo);
        base.Run();
    }
    /* ... */
}
This is just one possibility, but hopefully it gives you an idea of what's possible.

Good luck!

Viewing all articles
Browse latest Browse all 2297