SelfAction
self变量是事物执行自己的行为时把自己放入变量上下文的,因此当前self变量往往不是动作自己,因此如果动作需要self变量是自己,那么可以把自己定义成SelfAction。
While
以While为例,While类似于编程语言中的控制语句while。
编辑While的截图:
如图While继承了SelfAction,While的run的实现代码是:
package xworker.lang.actions; import org.xmeta.Action; import org.xmeta.ActionContext; import org.xmeta.Thing; import org.xmeta.World; public class WhileCreator { static World world = World.getInstance(); public static Object run(ActionContext actionContext) throws Exception{ Thing self = (Thing) actionContext.get("self"); actionContext.peek().isVarScopeFlag = true; Object result = "success"; while((Boolean) self.doAction("condition", actionContext, null, false)){ Thing childActions = self.getThing("ChildAction@0"); for (Thing child : childActions.getChilds()) { Action action = world.getAction(child); if (action != null) { result = action.run(actionContext, null, true); } int sint = actionContext.getStatus(); if (sint != ActionContext.RUNNING) { break; } } //判断循环的状态 if (actionContext.getStatus() == ActionContext.BREAK) { actionContext.setStatus(ActionContext.RUNNING); break; } else if (actionContext.getStatus() == ActionContext.CONTINUE) { actionContext.setStatus(ActionContext.RUNNING); continue; } else if (actionContext.getStatus() != ActionContext.RUNNING) { break; } } return result; } }
Copyright © 2007-2014 XWorker.org 版权所有