LED Access panel

Started by Maverick, Wed 30/11/2005 20:26:56

Previous topic - Next topic

Maverick

I've been trying to set up an access panel similar to the one in Demo Quest 3 (AGS Terminal) where interaction with the hotspots (that each represents a number on the keypad) will display the same decimal value (in the LED display) as the corresponding key on the keypad. There are ample examples of GUIs being used for this ( Dictator Anna,Scorpiorus,Ashen,Theatrx etc) but I couldn't find anything that pertains specifically to using hotspot interaction to trigger the display (closest was SSH's module).

I want the LED to display the key values as you interact with them starting from left to right i.e the rightmost value will move left every time another digit is entered (suppose I could use a string to make it easier on myself but keypads just don't work like that). The access code must have 4 digits and further to this it must display "Enter Code" before the first digit enetred. If incorrect display "Access Denied" etc. I am using objects to display the value in the LED by using object
  • . SetView(x,x,x) i.e to display a specific frame in a view made up from sprites (0 to 9).

    Anyone ot there that can assist?

Ashen

OK, since this has come up a few times lately, I've sort of developed this:

Set up your room with 10 hotspots and 4 objects.
The Objects:
0,1,2,3
Display digits. Set to not initially visible.

4
To display 'Enter Code' and 'Access Denied' messages. Line up with display, initially visible and set to 'Enter Code' graphic. This can be refered to be a scriptname (e.g. oDisplay instead of object[4]), if you'd rather.

The Hotspots:
1,2,3,4,5,6,7,8,9,10
Keys 1-9 and 0 respectively.

Put this at the top of your room script:
Code: ags

int sequence;
int code[4];

function Passcode(int number) {
  if (sequence == 0) object[4].Visible = false;
  object[sequence].Visible = true;
  object[sequence].SetView(codeview, codeloop, number);
  // Replace 'codeview' and 'codeloop' with the appropriate view & loop number
  code[sequence] = number;
  sequence ++;
  Wait(1);
  if (sequence == 4) {
    if (code[0] == 1 && code[1] == 2 && code[2] == 3 && code[3] == 4) {
      // The slightly crap code '1234' -  change the numbers to whatever you want the code to be.
      // Do whatever you want to happen when the right code is entered.
    }
    else { // Wrong code entered
      code[0] = -1;
      code[1] = -1;
      code[2] = -1;
      code[3] = -1;
      sequence = 0;
      object[0].Visible = false;
      object[1].Visible = false;
      object[2].Visible = false;
      object[3].Visible = false;
      //Reset everything
      object[4].Graphic = DENIED; // Change 'DENIED' to spriteslot of 'Access denied' sprite
      object[4].Visible = true;
      Wait(20);
      object[4].Graphic = ENTER; // Change 'ENTER' to spriteslot of 'Enter code' sprite
    }
  }
}


Set the hotspots to run Passcode(x) (where x is the number of the key, obviously), make the changes needed (codeview, codeloop, DENIED, ENTER) and it should be sorted. (As in, it works for me, but you might have to jiggle it a little depending on exactly how you want it.)
I know what you're thinking ... Don't think that.

Maverick

Thanks Ashen.
My initial code is very similar but my problem is that I cannot manage to get the digits to shift from right to left as you enter them.  In the example you gave the code is 1234 but will be displayed on the LED as 4321.

How would I go about doing that.

Ashen

If you mean like :
___1
__21
_321
4321

just change the positions of objects 0-3. (Unlikely, but just thought I'd mention it.)

If you mean:
1___
21__
321_
4321

You'll need to replace the line object[sequence].SetView(codeview, codeloop, number); (about line 7 of the above code) with:
Code: ags

  object[0].SetView(codeview, codeloop, number);
  if (object[1].Visible == true) object[1].SetView(codeview, codeloop, code[sequence-1]);
  if (object[2].Visible == true) object[2].SetView(codeview, codeloop, code[sequence-2]);
  if (object[3].Visible == true) object[3].SetView(codeview, codeloop, code[sequence-3]);

(Obviously, change codeview, codeloop as needed.)
I know what you're thinking ... Don't think that.

Khris

I think he wants it to be like:
___1
__12
_123
1234

Ashen

#5
That would make more sense, yes....

In that case, combine the two: put the objects left to right (3-2-1-0 rather than 0-1-2-3) - which, rereading your post it looks like you might already have done - AND make the change in the code.

I'd taken
Quotebut will be displayed on the LED as 4321.
as a request, rather than a complaint. Sorry about that, but hopefully it's sorted now.
I know what you're thinking ... Don't think that.

Maverick

Thanks Ashen!!!

Yup, moving the objects would also have "solved" the problem in the sence that the code would display the right way round but then the first digit would be inserted from left to right (somewhere out in the middle of display) and that was not exactly what I was looking for.

I set up the objects 3_2_1_0 to start with and your latest suggestion solved my problem i.e. digits now behave like a normal calculator (or just about any device with a keypad) as per khrismuc's reply.
Two thumbs up!!

:)

Ashen

#7
Heh, no worries, glad it's sorted.

The original problem was I somehow managed to skip "the rightmost value will move left every time another digit is entered" (from the first post) EVERY SINGLE TIME I read it.
I know what you're thinking ... Don't think that.

SMF spam blocked by CleanTalk