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

  1.  
  2. -- NOT_COMPLETE = 0;
  3. -- JUST_COMPLETE = 1;
  4. -- COMPLETE = 2;
  5.  
  6. function checkTutorial3Complete()
  7.  
  8.     -- if mission is already complete: return 2
  9.     if (retrieveData("complete")) then
  10.         return 2;
  11.     end
  12.  
  13.     -- check if mission is complete now
  14.     
  15.     -- needed objects list has to be empty
  16.     local neededObjects = retrieveData("neededObjects");
  17.     if getn(neededObjects) > 0 then
  18.         -- not complete
  19.         return 0;
  20.     end
  21.     
  22.     
  23.     -- check elaine
  24.     local elaine = getParent().getCharacter(ELAINE);
  25.  
  26.     if (not elaine) then
  27.         return 0;
  28.     end
  29.         
  30.     --local romantic = elaine.getRelationshipCondition(MIKE, REL_FRIENDSHIP);
  31.     --if romantic < 1 then
  32.         -- not complete
  33.     --    return 0;
  34.     --end
  35.     
  36.     -- check mike
  37.     local mike = getParent().getCharacter(MIKE);
  38.  
  39.     if (not mike) then
  40.         return 0;
  41.     end
  42.         
  43.     --romantic = mike.getRelationshipCondition(ELAINE, REL_FRIENDSHIP);
  44.     --if romantic < 1 then
  45.         -- not complete
  46.     --    return 0;
  47.     --end
  48.  
  49.     -- now complete: return 1
  50.     storeData("complete", 1);
  51.     return 1;
  52. end
  53.  
  54.  
  55. beginStateMachine()
  56.  
  57.     onEnter(function(msg)
  58.         -- list of useful things that have to be built
  59.         storeData("neededObjects", {"lamp", "kommode", "tv", "plant", "flower"});
  60.         popupMission();
  61.     end )
  62.  
  63.     onMsg("getText", function(msg)
  64.         -- set mission text
  65.         if (checkTutorial3Complete() == 0) then
  66.             -- mission is not yet complete
  67.             setMissionText("tutorial3_name", "tutorial3_desc");
  68.         else
  69.             -- mission is complete
  70.             setMissionText("tutorial3_name", "tutorial3_finish");
  71.         end
  72.     end )
  73.  
  74.  
  75.     onMsg("buy", function(msg)
  76.         -- check if something useful was built
  77.         local sender = getStateObjectFromID(msg.sender);
  78.  
  79.         local neededObjects = retrieveData("neededObjects");
  80.  
  81.         for i = 1, getn(neededObjects) do
  82. print("checking needed object " .. neededObjects[i]);
  83.             if sender.hasBehavior(neededObjects[i]) then
  84. print("found");
  85.                 -- remove from needed objects and store needed objects again
  86.                 tremove(neededObjects, i);
  87.                 storeData("neededObjects", neededObjects);
  88.  
  89.                 -- remove a moving carton
  90.                 local cartons = sender.getObjectsWithBehavior("movingCarton");
  91.                 if getn(cartons) > 0 then
  92. print("delete");
  93.                     cartons[1].deleteGameObject();
  94.                 end
  95.  
  96.                 break;
  97.             end
  98.         end
  99.     end )
  100.     
  101.     onMsg("checkComplete", function(msg)
  102.         if (checkTutorial3Complete() == 1) then
  103.             popupMission();
  104.         end
  105.     end )
  106.     
  107.     onMsg("ok", function(msg)
  108.         print("3 ok pressed");
  109.         if (checkTutorial3Complete() == 2) then
  110.             exitStateMachine();
  111.         end
  112.     end )
  113.  
  114.     endStateMachine()
  115.