Where have i gone wrong here? [SOLVED]

Started by sazterM, Wed 12/11/2008 15:56:10

Previous topic - Next topic

sazterM

Ive been trying to get this to work for quite a while, but i give up - could someone tell me where iv'e gone wrong. Bear in mind that i'm a TOTAL noobie at this and have probably approached this in completely the wrong way.

What i'm trying to do is have the room change after 3 switches have been triggered - which i have been able to do BUT, the following script i wanted to have the player say different things depending on how many of the switches have been triggered (in any order).

Iv'e managed to get the first two parts to work i.e. the MC says different things if 1 switch has been pulled when the second one is. After this however, it doesnt let me even select the third switch in game. I'm totally confused, any advice wouuld be appreciated. Sorry if my explanation isnt very clear but heres the script i'm having problems with:


Code: ags
function hHotspot9_UseInv()
  {
     if (player.ActiveInventory == iChairleg)
     if (switches == 0)
  {
      switches = 1;
      player.Walk(75, 103, eBlock, eWalkableAreas);
      player.FaceLocation(86, 45);
      trigger1 = true;
      oTorch1.Visible = true; 
      player.Say("Looks like there's some kind of mechanism behind the bracket...");
      Wait(25);
      oTorch1.Visible = false;
      oTorch1s.Visible = true;
      PlaySound(2);
      Wait(40);
      oTorch1s.Visible = false;
      Wait(15);
      player.Say("Nothing seems to have happened, maybe there's something more i have to do..."); 
    
     }
     else if (switches == 1)
          if (player.ActiveInventory == iChairleg)
     {
      switches = 2;
      player.Walk(75, 103, eBlock, eWalkableAreas);
      player.FaceLocation(86, 45);
      trigger1 = true;
      oTorch1.Visible = true; 
      player.Say("Looks like there's some kind of mechanism behind the bracket...");
      Wait(25);
      oTorch1.Visible = false;
      oTorch1s.Visible = true;
      PlaySound(2);
      Wait(40);
      oTorch1s.Visible = false;
      Wait(15);
      player.Say("Hasn't done the trick yet.");
     
     }
     else if (switches == 2)
          if (player.ActiveInventory == iChairleg)
    {
      player.Walk(75, 103, eBlock, eWalkableAreas);
      player.FaceLocation(86, 45);
      trigger1 = true;
      oTorch1.Visible = true; 
      player.Say("Looks like there's some kind of mechanism behind the bracket...");
      Wait(25);
      oTorch1.Visible = false;
      oTorch1s.Visible = true;
      PlaySound(2);
      Wait(40);
      oTorch1s.Visible = false;
      Wait(15);
      player.Say("That's got it!");
     }
    }
  

    // END OF FUNCTION //////////////////////////////////////////////
      
     function hHotspot10_UseInv()
  {
     if (player.ActiveInventory == iChairleg)
     if (switches == 0)
    {    
   switches = 1;
      player.Walk(138, 96, eBlock, eWalkableAreas);
      player.FaceLocation(144, 35);
      trigger2 = true;
      oTorch2.Visible = true; 
      player.Say("Looks like there's some kind of mechanism behind the bracket...");
      Wait(25);
      oTorch2.Visible = false;
      oTorch2s.Visible = true;
      PlaySound(2);
      Wait(40);
      oTorch2s.Visible = false;
      Wait(15);
      player.Say("Nothing seems to have happened, maybe there's something more i have to do...");
  }
     else if (switches == 1)
          if (player.ActiveInventory == iChairleg)
  {
      switches = 2;
      player.Walk(138, 96, eBlock, eWalkableAreas);
      player.FaceLocation (144, 35);
      trigger2 = true;
      oTorch2.Visible = true; 
      player.Say("Looks like there's some kind of mechanism behind the bracket...");
      Wait(25);
      oTorch2.Visible = false;
      oTorch2s.Visible = true;
      PlaySound(2);
      Wait(40);
      oTorch2s.Visible = false;
      Wait(15);
      player.Say("Hasn't done the trick yet.");
    }
     else if (switches == 2)
          if (player.ActiveInventory == iChairleg)
    {
      player.Walk(138, 96, eBlock, eWalkableAreas);
      player.FaceLocation(144, 35);
      trigger2 = true;
      oTorch2.Visible = true; 
      player.Say("Looks like there's some kind of mechanism behind the bracket...");
      Wait(25);
      oTorch2.Visible = false;
      oTorch2s.Visible = true;
      PlaySound(2);
      Wait(40);
      oTorch2s.Visible = false;
      Wait(15);
      player.Say("That's got it!");
    }
  
    } 
  
      // END OF FUNCTION /////////////////////////////////////////////
      
     function hHotspot11_UseInv()
  {   
      if (player.ActiveInventory == iChairleg)
      if (switches == 0)
      {    
      switches = 1;
      player.Walk(166, 95, eBlock, eWalkableAreas);
      player.FaceLocation(180, 32);
      trigger3 = true;
      oTorch3.Visible = true; 
      player.Say("Looks like there's some kind of mechanism behind the bracket...");
      Wait(25);
      oTorch3.Visible = false;
      oTorch3s.Visible = true;
      PlaySound(2);
      Wait(40);
      oTorch3s.Visible = false;
      Wait(15);
      player.Say("Nothing seems to have happened, maybe there's something more i have to do...");
  
     }
      else if (switches == 1)
           if (player.ActiveInventory == iChairleg)
     {
      switches = 2;
      player.Walk(166, 95, eBlock, eWalkableAreas);
      player.FaceLocation(180, 32);
      trigger3 = true;
      oTorch3.Visible = true; 
      player.Say("Looks like there's some kind of mechanism behind the bracket...");
      Wait(25);
      oTorch3.Visible = false;
      oTorch3s.Visible = true;
      PlaySound(2);
      Wait(40);
      oTorch3s.Visible = false;
      Wait(15);
      player.Say("Hasn't done the trick yet.");
     }
     else if (switches == 2)
          if (player.ActiveInventory == iChairleg)
     {
      player.Walk(166, 95, eBlock, eWalkableAreas);
      player.FaceLocation(180, 32);
      trigger3 = true;
      oTorch3.Visible = true; 
      player.Say("Looks like there's some kind of mechanism behind the bracket...");
      Wait(25);
      oTorch3.Visible = false;
      oTorch3s.Visible = true;
      PlaySound(2);
      Wait(40);
      oTorch3s.Visible = false;
      Wait(15);
      player.Say("That's got it!");
     }
  }

Khris

#1
Here's the code for Hotspot9:

Code: ags
function hHotspot9_UseInv() {
  if (player.ActiveInventory != iChairleg) player.Say("That won't work.");
  else {   // iChairleg was used
    player.Walk(75, 103, eBlock, eWalkableAreas);
    player.FaceLocation(86, 45);

    if (trigger1) {
      player.Say("There's nothing more I can do with chair leg here.");
      return;  //exit
    }
    trigger1 = true;

    oTorch1.Visible = true; 
    player.Say("Looks like there's some kind of mechanism behind the bracket...");
    Wait(25);
    oTorch1.Visible = false;
    oTorch1s.Visible = true;
    PlaySound(2);
    Wait(40);
    oTorch1s.Visible = false;
    Wait(15);
    if (switches==0) player.Say("Nothing seems to have happened, maybe there's something more i have to do..."); 
    if (switches==1) player.Say("Hasn't done the trick yet.");
    if (switches==2) player.Say("That's got it!");
    switches++;
  }
}



EDIT:
Even better:

Code: ags
//room script

bool trigger[4];

function UseChairLeg(int x, int y, Object*o1, Object*o2, int triggerindex) {
  player.Walk(x, y, eBlock, eWalkableAreas);
  player.FaceLocation(x, y-5);

  if (trigger[triggerindex]) {
    player.Say("There's nothing more I can do with chair leg here.");
    return;  //exit
  }
  trigger[triggerindex] = true;

  o1.Visible = true; 
  player.Say("Looks like there's some kind of mechanism behind the bracket...");
  Wait(25);
  o1.Visible = false;
  o2.Visible = true;
  PlaySound(2);
  Wait(40);
  o2.Visible = false;
  Wait(15);
  if (switches==0) player.Say("Nothing seems to have happened, maybe there's something more i have to do..."); 
  if (switches==1) player.Say("Hasn't done the trick yet.");
  if (switches==2) player.Say("That's got it!");
  switches++;
}

function hHotspot9_UseInv() {
  if (player.ActiveInventory != iChairleg) player.Say("That won't work.");
  else UseChairLeg(75, 103, oTorch1, oTorch1s, 1);
}

function hHotspot10_UseInv() {
  if (player.ActiveInventory != iChairleg) player.Say("That won't work.");
  else UseChairLeg(138, 96, oTorch2, oTorch2s, 2);
}

function hHotspot11_UseInv() {
  if (player.ActiveInventory != iChairleg) player.Say("That won't work.");
  else UseChairLeg(166, 95, oTorch3, oTorch3s, 3);
}


Proper indentation!

sazterM


SMF spam blocked by CleanTalk