Custom macros are not available

    skipArgs : true,
    tags   : null,
    handler: function() {
        var medicineName = this.args[0];
        var duration = parseInt(this.args[1]);

        var displayDiv = document.createElement('div');

        var timerDisplay = document.createElement('p');

        var startButton = document.createElement('button');
        startButton.textContent = '开始';

        var pauseButton = document.createElement('button');
        pauseButton.textContent = '暂停';

        var seconds = 0;
        var interval;

        function updateTimer() {
            timerDisplay.textContent = medicineName + ' - ' + seconds + 's';
            seconds += 1;

        startButton.addEventListener('click', function() {
            interval = setInterval(updateTimer, 1000);

        pauseButton.addEventListener('click', function() {

        updateTimer(); // 初始化显示

        // 设置持续时间
        setTimeout(function() {
            timerDisplay.textContent = medicineName + ' - 完成';
        }, duration * 1000); // 将持续时间转换为毫秒

Error: cannot find a closing tag for macro <>

<<displayMedicineDurationWithControls 复活节 5>>

tags: null means that it should require a closing tag, so you’d need a <</displayMedicineDurationWithControls>>

If you want it to be “self-closing” then you leave out the tags. Setting tags:null means that it can have content in between the opening and closing tags but that there are no special child tags (<<else>> between <<if>> and <</if>> would be an example of a child tag).

You also want to delete the skipArgs: true line: that says that SugarCube should not parse the macro’s arguments into this.args[0] and this.args[1]: the only thing that will be set is this.args.full and this.args.raw, I believe.

And finally, are you redefining the whole interface with StoryInterface? Because on the default SugarCube UI, your current code puts the output in a place that isn’t visible. So if you see that happening, you might want to use this.output instead of document.body. But I’m guessing you are using a custom UI.

1 Like