Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Maverick on Wed 30/11/2005 20:26:56

Title: LED Access panel
Post by: Maverick on Wed 30/11/2005 20:26:56
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
Title: Re: LED Access panel
Post by: Ashen on Thu 01/12/2005 00:29:03
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:

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.)
Title: Re: LED Access panel
Post by: Maverick on Thu 01/12/2005 18:14:30
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.
Title: Re: LED Access panel
Post by: Ashen on Thu 01/12/2005 20:12:09
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:

  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.)
Title: Re: LED Access panel
Post by: Khris on Thu 01/12/2005 21:40:12
I think he wants it to be like:
___1
__12
_123
1234
Title: Re: LED Access panel
Post by: Ashen on Thu 01/12/2005 21:50:22
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.
Title: Re: LED Access panel
Post by: Maverick on Fri 02/12/2005 08:05:17
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!!

:)
Title: Re: LED Access panel
Post by: Ashen on Fri 02/12/2005 11:20:40
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.