用户:
AbnormalLOG查看:1 回复:2 评论:1 创建时间:2021-08-16T19:38:21
代码如下: world.eventlobj={} varEvent=class{ constructor(eventfunciton/*当条件达成时执行的函数*/,statefunction/*条件函数,返回布尔值*/,name/*事件对象的名字*/){ world.eventlobj[name]=this this.statelst=[] this.eventfunciton=eventfunciton this.statefunction=statefunction this.name=name this.ticker=world.onTick(()=>{ vars=statefunction() this.statelst.push(s) if(s!=this.statelst[this.statelst.length-2]){ if(s==true){ eventfunciton() } } }) this.cancel=this.ticker.cancel/*取消处理事件*/ this.resume=this.ticker.resume/*继续处理事件*/ } } 使用方法: 新的事件: varevent=newEvent(函数1,函数2,名字) 函数1是事件执行函数,当满足函数2的条件时就可以执行 函数2是条件函数,需要返回值true或者false。true是满足,false是不满足. 使用代码:事件对象.cancel()可以取消事件处理器 事件对象.resume可以继续监听处理器 要搜索处理器时,直接用world.eventobj[处理器名字]即可 又是一个喵
我的排版……😭
代码如下:
world.eventlobj = {}
var Event = class {
constructor(eventfunciton/*当条件达成时执行的函数*/, statefunction/*条件函数,返回布尔值*/, name/*事件对象的名字 */) {
world.eventlobj[name] = this
this.statelst = []
this.eventfunciton = eventfunciton
this.statefunction = statefunction
this.name = name
this.ticker = world.onTick(() => {
var s = statefunction()
this.statelst.push(s)
if (s != this.statelst[this.statelst.length - 2]) {
if (s == true) {
eventfunciton()
}
}
})
this.cancel = this.ticker.cancel/*取消处理事件*/
this.resume = this.ticker.resume/*继续处理事件*/
}
}
使用new Event(函数1,函数2,名字)就可以创建一个事件处理器
函数1是事件执行函数,当满足函数2的条件时就可以执行 函数2是条件函数,需要返回值true或者false。true是满足,false是不满足.
如果要搜索事件处理器,直接可以用world.eventobj[事件处理器名字]就可以搜索到
取消处理器和继续的函数和Box3EventHandlerToken一样.
最后的最后的最后
这只是一个Smuggled goods(水 --- 货)![]()