home *** CD-ROM | disk | FTP | other *** search
- -- lamp state machine
-
- beginStateMachine()
-
- onMsg("buildMenu", function(msg)
-
- if (repairMenu()) then return end
-
- -- build the pie menu
- clearPieMenu();
- local button ;
- if (this.getLightOn()) then
- button = addPieMenuButton("pm_switchOff", "switchoff");
- -- button.addIcon("guiIconComfort");
- else
- button = addPieMenuButton("pm_switchOn", "switchon");
- -- button.addIcon("guiIconComfort");
- end
-
- button.addDescription(USERACTION, "true");
- end )
-
- onMsg("switchon", function(msg)
- -- setLightColor(1,1,1);
- this.unlock(); -- for random breaking
- if (not this.isBroken()) then
- playSound("switchOn");
- setLightOn(true);
- end
- end )
-
- onMsg("switchoff", function(msg)
- -- setLightColor(0,0,0.4);
- playSound("switchOff");
- setLightOn(false);
- end )
-
-
- -- repair
- onMsg("repair", function(msg)
-
- print("onMsg repair");
- -- get character who initiated this action
- local character = getStateObjectFromID(msg.sender);
- -- walk to the closest action point
- local actionPoint = character.getClosestFreeActionPoint(character, this, {"repair1", "repair2", "repair3", "repair4"});
- -- get the walk state object
- local wso = character.walkSO;
- if (actionPoint) then
- -- create state machine contexts
- local wsoContext = StateMachineContext();
- -- store the action point
- wsoContext.storeData("actionPointName", actionPoint.getName());
- if (wso.walkToActionPoint(actionPoint)) then
- wso.queueStateMachine("repairChar.repairStart", this, wsoContext);
- else
- print("no path found");
- instantAbort(character, EMOTICON_NOPATH, "emoThink")
- end
- else
- print("no action point found");
- instantAbort(character, EMOTICON_CANNOT, "emoThink")
- end
- end )
-
-
- endStateMachine()
-