Script Issues

Started by metalmario991, Fri 25/01/2019 03:37:09

Previous topic - Next topic

metalmario991

I have two issues with the following script.
1) For some reason, the characters does some of the interactions, such as the look and open twice. I don't know why, but they keep doing that.
2) Some produce nothing at all, like Use.
2) The script for using the crowbar doesn't seem to work.

What's wrong here?

Code: ags
  if (MovePlayer(188, 79)) {
  player.FaceDirection(eDirectionUp);
  // LOOK AT
  if(UsedAction(eGA_LookAt)) {
  player.Say("These doors are our only obstacle in getting into the Stadium.");
  }
  // OPEN
  else if(UsedAction(eGA_Open)) {
      if (UsedCrowbar == false) {
       if (player == cMikePrologue) {
       player.ChangeView(33);
        player.Animate(3, 4, eOnce, eBlock, eForwards);
        player.ChangeView(32);
        player.Say("Hmmmm, this door appears to be locked.");
       }
       else {
        player.ChangeView(41);
        player.Animate(3, 4, eOnce, eBlock, eForwards);
        player.ChangeView(48);
        player.Say("Hmmmm, this door appears to be locked.");
       }
      }
      else {
      if (player == cMikePrologue) {
        player.ChangeView(33);
        player.Animate(3, 4, eOnce, eBlock, eForwards);
        aDoorOpe.Play(eAudioPriorityNormal);
        player.ChangeView(32);
        oDoors.Visible = false;
        oOpenDoors.Visible = true;
      }
      else {
        player.ChangeView(41);
        player.Animate(3, 4, eOnce, eBlock, eForwards);
        aDoorOpe.Play(eAudioPriorityNormal);
        player.ChangeView(48);
        oDoors.Visible = false;
        oOpenDoors.Visible = true;
      }
      }
  }
  }
     // CLOSE
  else if(UsedAction(eGA_Close)) {
    player.Say("It's already closed.");
  }
  // Push
  else if(UsedAction(eGA_Push)) {
  Unhandled();
  }
  
  // Pull
  else if(UsedAction(eGA_Pull)) {
  player.Say("It's a push door.");
  } 
  //USE INV
  else if(UsedAction(eGA_UseInv)) {
    if (player.ActiveInventory == iCrowbar) {
      if (UsedCrowbar == false) {
        if (player == cMikePrologue) {
          player.FaceDirection(eDirectionDown);
          player.Say("Normally, I don't advocate vandalisim.");
          player.FaceDirection(eDirectionUp);
          player.Say("But we can't find out what crashed in the stadium otherwise...");
          player.ChangeView(33);
          player.Animate(3, 4, eOnce, eBlock, eForwards);
          aBreak.Play(eAudioPriorityNormal);
          oDoors.Visible = false;
          oOpenDoors.Visible = true;
          player.ChangeView(32);
          player.Say("Whoops, I think I broke the lock.");  
        }
        else {
          player.FaceDirection(eDirectionDown);
          player.Say("I'm not sure forcing open the door with this old crowbar is a good idea...");
          player.FaceDirection(eDirectionUp);
          player.Say("HOWEVER, we need to get inside that Stadium!");
          player.ChangeView(33);
          player.Animate(3, 4, eOnce, eBlock, eForwards);
          aBreak.Play(eAudioPriorityNormal);
          oDoors.Visible = false;
          oOpenDoors.Visible = true;
          player.ChangeView(32);
          player.Say("Yikes, I broke the lock. I hope this isn't traced back to us...");  
        }
      }
      else {
      player.Say("I broke the lock, no need to use the crowbar anymore.");
      }
    }
    else {
    player.Say("I don't think that's gonna work.");
    }
  }
  else Unhandled();
}

metalmario991

OK, while messing around I figured out the twice problem.

The UseInv, Close, and all the Unhandled scripts aren't working at all.

Khris

#2
One word: INDENTATION.

If you use proper indentation from the start, you are much less likely to make bracket errors. The code you posted shouldn't even compile because there's an additional } after the OPEN block.

PS:
You can auto-format your code if you paste it in the JavaScript area on the lower left here, then click the Tidy button in the top bar.

Snarky

When you post code, please wrap it in [code=ags]your code here[/code] tags. I've taken the liberty of editing your post to add that.

As Khris says, the next step is to use correct indentation. By doing this you can much more easily see how the different IFs and ELSEs are nested, and thereby follow the logic of the code.

metalmario991

Thanks, that fixed it. I should use that Tidy fix more often, as it seems easy to make a mistake when you have a bunch of nested stuff like that.
Sorry about the code tags, I didn't know that's how you get it like that.

SMF spam blocked by CleanTalk