Author Topic: Script Help Please  (Read 623 times)

Legacy_0-Djanga-0

  • Newbie
  • *
  • Posts: 10
  • Karma: +0/-0
Script Help Please
« on: September 06, 2015, 01:34:38 am »


               

This script is modified from HotU. It has a floor arrow that is supposed to unlock the thing it is facing (the arrow spins). In this one there are 2 chests and a door. The door unlocks as it should but the chests do not. All tags are set right. The script is set on the arrow (floor design)


If some one could figure out why the chests do not unlock I would appreciate it.



///////////////////////////////////////////////////////////////////////////////////
// This script will lock an unlock objects depending on which way the arrow faces.
//
// Created by: Brad Prince
// 9-17-02
//
//////////////////////////////////////////////////////////////////////////////////

void main()
{
   /* The arrow visually faces the opposite direction of the "Facing" on the
      object, so reverse the meaning of the direcions.
      Also, East is 0.0, counter clockwise to north at 90.0, etc.
   */

   float ARROW_NORTH = 270.0;
   float ARROW_WEST  =   180.0;
   float ARROW_SOUTH =  90.0;
   int   NORTH =  90;
   int   EAST  =   0;
   int   SOUTH = 270;
   int   WEST  = 180;

   float fFacing = GetFacing(OBJECT_SELF);
   // Flip the fFacing to represent the way the arrow is actually pointing.
   int   aFacing = (FloatToInt(fFacing) + 180) % 360;

   object oNorth = GetObjectByTag("chest_north");
   object oSouth = GetObjectByTag("chest_south");
   object oWest  = GetObjectByTag("door_west");
   // Variable for random direction calculating.
   int x;
   if (oNorth==OBJECT_INVALID){SpeakString ("north invalid");}
   if (oSouth==OBJECT_INVALID){SpeakString ("south invalid");}
   // Query the current direction.
   if(aFacing > (NORTH-5) && aFacing < (NORTH+5)) {
      // Arrow is currently facing North
       x = 1;
    }
    else if(aFacing > (SOUTH-5) && aFacing < (SOUTH+5)) {
       // Arrow is currently facing South
       x = 2;
    }
    else if(aFacing > (WEST-5)  && aFacing < (WEST+5)) {
       // Arrow is currently facing West
       x = 4;
    }
    else {
       // This one (east) isn't used.
       x = 3;
    }
   // Have us say something.
   SpeakString("(was x = " + IntToString(x) + ", arrow facing " + IntToString(aFacing) + ")" );

   switch(x) {
   case 1:
      // Originally North, change to South
      if(!GetIsOpen(oNorth)) {
         SetLocked(oNorth, 1);
      }
      SetLocked(oSouth, 0);
      SetLocked(oWest, 1);
      AssignCommand(oWest, ActionCloseDoor(OBJECT_SELF));
      SetFacing(ARROW_SOUTH);
      SpeakString("1 south chest unlocked");
      break;
   case 2:
      // Originally South, change to West
      if(!GetIsOpen(oNorth)) {
         SetLocked(oNorth, 1);
      }
      if(!GetIsOpen(oSouth)) {
         SetLocked(oSouth, 1);
      }
      SetLocked(oWest, 0);
      SetFacing(ARROW_WEST);
      SpeakString("2 west door unlocked");
      break;
   case 3:
      // Originally West, change to North
      SetLocked(oNorth, 0);
      if(!GetIsOpen(oSouth)) {
         SetLocked(oSouth, 1);
      }
      SetLocked(oWest, 1);
      AssignCommand(oWest, ActionCloseDoor(OBJECT_SELF));
      SetFacing(ARROW_NORTH);
      SpeakString("3 north chest unlocked");
      break;
   default:
      SetLocked(oNorth, 1);
      SetLocked(oSouth, 1);
      SetLocked(oWest, 1);
      AssignCommand(oWest, ActionCloseDoor(OBJECT_SELF));
      SetFacing(DIRECTION_WEST);
      SpeakString("Default");
      break;
   }
   SpeakString("(now x = " +IntToString(x)+", arrow facing "+FloatToString(GetFacing(OBJECT_SELF)) + ")" );
}


               
               

               
            

Legacy_MrZork

  • Hero Member
  • *****
  • Posts: 1643
  • Karma: +0/-0
Script Help Please
« Reply #1 on: September 06, 2015, 08:27:20 am »


               

You have debug lines in there. What do they print out for the cases you test? That might help someone pinpoint what's going on.


 


Meanwhile, some possibilities:


 


It looks like you have set x=1 when facing north, but your switch for 1 unlocks the south placeable. Similarly, when you set x=2 (south), the switch unlocks the west placeable. And, when you set x=4 (west), the switch hits the default, locking everything. Finally, when x is set to 3, the switch unlocks the north placeable.


 


There may also be some timing consideration. I.e., the arrow facing is read near the start and where it is pointing is determined from that. But, the script also sets the facing when the switch runs (which might appear to be immediate to the player). Why do that if the arrow is already facing that direction?


 


Also, I haven't tested it, but it looks like you are using the +180 method for the SetFacing calls (e.g. North = 90+180), and I seem to recall that that was necessary for GetFacing. But, the lexicon has the SetFacing function using facings without the +180 (e.g. North = 90). It seems likely that either the +180 should not be added or the lexicon needs some clarification.



               
               

               
            

Legacy_0-Djanga-0

  • Newbie
  • *
  • Posts: 10
  • Karma: +0/-0
Script Help Please
« Reply #2 on: September 06, 2015, 09:16:54 am »


               

Thank you, I'll have a look at this. And let you know the debug messages if none of your possible suggestions work. '<img'>



               
               

               
            

Legacy_0-Djanga-0

  • Newbie
  • *
  • Posts: 10
  • Karma: +0/-0
Script Help Please
« Reply #3 on: September 07, 2015, 12:36:34 am »


               

It was off by 90 degrees. Thank you for your help '<img'>