home *** CD-ROM | disk | FTP | other *** search
/ Singles (French) / Singles-FrenchVersion-Win95.iso / data1.cab / Statemachine / lamp.lua < prev    next >
Text File  |  2004-03-05  |  2KB  |  68 lines

  1. -- lamp state machine
  2.  
  3. beginStateMachine()
  4.  
  5.     onMsg("buildMenu", function(msg)
  6.     
  7.         if (repairMenu()) then return end
  8.         
  9.         -- build the pie menu
  10.         clearPieMenu();
  11.         local button ;
  12.         if (this.getLightOn()) then
  13.             button = addPieMenuButton("pm_switchOff", "switchoff");
  14.             -- button.addIcon("guiIconComfort");
  15.         else
  16.             button = addPieMenuButton("pm_switchOn", "switchon");
  17.             -- button.addIcon("guiIconComfort");
  18.         end
  19.         
  20.         button.addDescription(USERACTION, "true");
  21.     end )
  22.  
  23.     onMsg("switchon", function(msg)
  24.         -- setLightColor(1,1,1);
  25.         this.unlock(); -- for random breaking
  26.         if (not this.isBroken()) then
  27.             playSound("switchOn");
  28.             setLightOn(true);
  29.         end
  30.     end )
  31.  
  32.     onMsg("switchoff", function(msg)
  33.         -- setLightColor(0,0,0.4);
  34.         playSound("switchOff");
  35.         setLightOn(false);
  36.     end )
  37.     
  38.     
  39.     -- repair
  40.     onMsg("repair", function(msg)
  41.     
  42.         print("onMsg repair");
  43.         -- get character who initiated this action
  44.         local character = getStateObjectFromID(msg.sender);
  45.         -- walk to the closest action point
  46.         local actionPoint = character.getClosestFreeActionPoint(character, this, {"repair1", "repair2", "repair3", "repair4"});
  47.         -- get the walk state object
  48.         local wso = character.walkSO;
  49.         if (actionPoint) then
  50.             -- create state machine contexts
  51.             local wsoContext = StateMachineContext();
  52.             -- store the action point
  53.             wsoContext.storeData("actionPointName", actionPoint.getName());
  54.             if (wso.walkToActionPoint(actionPoint)) then
  55.                 wso.queueStateMachine("repairChar.repairStart", this, wsoContext);
  56.             else
  57.                 print("no path found");
  58.                 instantAbort(character, EMOTICON_NOPATH, "emoThink")
  59.             end
  60.         else
  61.             print("no action point found");
  62.             instantAbort(character, EMOTICON_CANNOT, "emoThink")
  63.         end
  64.     end )    
  65.  
  66.             
  67. endStateMachine()
  68.