|
楼主 |
发表于 2015-11-14 08:43:12
|
显示全部楼层
RE: 改良v0.2
改良了一下,增加完成执行完命令后的回调方法与停止后的回调方法
另外修改原有不能立即停止的bug
var p_isStop = false;
var p_isPause = false;
//记录暂停房间
var p_pauseRoomId = "";
//默认由多个|号分割的命令,按second的间隔执行秒,
//start为执行的方法位置:例如:cmdstr为func1()|func2(),当start为0即执行func1(),为1即执行func2()
//type为执行类型10为命令,12为方法
//callback为执行完命令后的回调方法
//stopcallback为停止后的回调方法
function doAfterSpecial3(cmdstr,second,type,start,callback,stopcallback){
if(start == null){
start = 0;
}
if(type == null){
type = 12;
}
if(second < 0.5 || second > 100){
world.Note("间隔超出范围");
}
if(callback == null){
callback = "";
}
if(stopcallback == null){
stopcallback = "";
}
var cmds = cmdstr.split("|");
if(cmds.length <= start){
world.Note("doAfterSpecial3:执行完成");
if(callback != ""){
eval(callback+"()");
}
return;
}
if(p_isStop){
world.Note("doAfterSpecial3:停止");
if(stopcallback != ""){
//p_doAfterSpecial3_stopcallback();
eval(stopcallback+"()");
}
return;
}
var cmd = cmds[start];
start++;
var fcmd = "world.DoAfterSpecial(0.1,\\\""+cmd+"\\\","+type+");";
if(type == 10){
fcmd = "world.Execute(\\\""+cmd+"\\\");";
}else if(type = 12){
fcmd = "eval(\\\""+cmd+"\\\");";
}
var fcmd2 = "doAfterSpecial3(\\\""+cmdstr+"\\\","+second+","+type+","+start+",\\\""+callback+"\\\",\\\""+stopcallback+"\\\")";
if(callback == ""){
if(stopcallback == ""){
fcmd2 = "doAfterSpecial3(\\\""+cmdstr+"\\\","+second+","+type+","+start+")";
}
}else{
if(stopcallback == ""){
fcmd2 = "doAfterSpecial3(\\\""+cmdstr+"\\\","+second+","+type+","+start+",\\\""+callback+"\\\")";
}
}
fcmd += fcmd2;
world.DoAfterSpecial(second,"canExcute(\""+fcmd+"\")",12);
}
function canExcute(cmd){
if(p_isPause){
cmd = cmd.replace(/'/g,"\\\'");
world.DoAfterSpecial(5,"canExcute('"+cmd+"')",12);
}else{
//world.Note("canExcute:"+cmd);
//world.DoAfterSpecial(0.1,cmd,12);
eval(cmd);
}
}
function test1(){
world.Note("callback");
}
function test2(){
world.Note("stopcallback");
}
调用方法:doAfterSpecial3("world.Note('n')|world.Note('n')|world.Note('west')","2","12",0,"test1","test2") |
|