We've split up the commands, scripting and mods, and add ons category! Please be sure you get your thread in the right place.

18

Allow macros to be used with /schedule

1 Comments

Please sign in to leave a comment.

Sorted by oldest
  • 1
    Registered User commented
    Comment actions Permalink

    认同,目前 schedule 函数不允许通过宏传入参数,对于数据包开发者,这会为他们整合大量重复函数带来极大的困难。允许 schedule 使用宏将会使他们获得便利。

    因此, 根据楼主的说法,schedule 使用 function 时的语法应该是:

    schedule function <function> {Param1:... , Param2:... , ...} <time> [append/replace]

    我个人有一种更加理想的方案。改变 schedule 的语法,若要通过它执行一些东西,先通过 delay 声明执行的延迟(作用是与 clear 区分开,避免语法混淆),同时将 function 更名为 run , 允许其直接执行一个指令,通过指令执行 function 也能达到对宏的使用。同时,还能做到延时检查目标状态等复杂的功能。

    此外,在run的基础下增添一个可选的tag选项,以此标记所执行的延时计划,方便 schedule clear语句清除计划。

     

    因此,个人理想中的语法如下:

    schedule delay <time> [append/replace] [tag <tagName> [tag <tagName> [...]]] run <command>
    schedule clear <tagName>

    此外,个人还有几个例子对该语法加以解释说明:

    #在1秒钟后对函数传参并执行
    schedule delay 1s run function foo:bar {param1:... , param2:...}

    #在10游戏刻后输出helloworld,并为语句添加 test 标记
    schedule delay 10t tag test run say helloworld

    #在20游戏刻后嵌套一个新的schedule,执行函数,并为第一个schedule添加test和example标记
    schedule delay 20t tag example tag test run schedule delay 10t run function foo:bar

    #在5游戏刻后检查最近玩家的谓词(假设为holding_sword),若执行成功,清除标记为test的语句
    schedule delay 5t run execute as @n if predicate holding_sword run schedule clear test

    #这些例子都表明了该函数语法的功能强大。而且该语法具有很强的可扩展性,未来的更新还可以在tag、run、delay的基础上增加更多的语法规则