MODULE: Hotspot ComboLock
by Nik 'Ashen' Mallon.

Dependancies: AGS Version 2.7+ (should be fully compatable with 2.71)

Abstract:
Yet another Passcode Lock Module, this one designed to use hotspots and objects, rather than a GUI.

Mmm, what?:
This is basically a module-ised version of code I posted in a thread on the AGS Forums (http://www.bigbluecup.com/yabb/index.php?topic=23748.0), with a few functional changes.


How it works:
Firstly, set up a view - or an unused loop within an existing view, with images of the numbers 0-9, in that order.
(As a side note, you're not technically limited to numbers, you could also have letters or symbols. You are, however, currently limited to 20 of them - number of frames per loop - without a little creative scripting.)

Then, you need to set up your room. Use Hotspots for the buttons (obviously, kind of the point of the module), and create 4 objects to act as the display. NOTE: THESE MUST BE OBJECTS 0, 1, 2, AND 3. Set them up Right-Left (i.e. [3][2][1][0] not [0][1][2][3]) where you want the display.


The Functions:
HotspotLock.SetCode(int first, int second, int third, int fourth, int view, int loop):

Call this to set up the keypad - one of the 'Player enters room' interactions is probably best.
Enter your code as four seperate digits, then the View and loop your sprites are in, e.g. 'code = 1979, sprites are in loop 2 of view 5:
HotspotLock.SetCode(1, 9, 7, 9, 5, 2);

HotspotLock.EnterCode(int number):

What number you want the hotspot to represent, e.g.
// Any click on Hotspot 1
HotspotLock.EnterCode(1);

HotspotLock.CheckCode():
What it says. Call this from a hotspot, or rep_ex, to check iif the right code has been entered. Has three return values: eCodeNoCode, when less than 4 digits have been entered; eCodeCorrect, for when the Correct Code had been entered; and eCodeWrong, you can probably guess at. E.g.
  // script for Room: Repeatedly execute
  if (HotspotLock.CheckCode() == eCodeCorrect) {
    //Code entered correctly
    Display("Well Done!");
    player.ChangeRoom(10, 120, 200);
  }
  else if (HotspotLock.CheckCode() == eCodeWrong) {
    // Wrong code entered.
    Display ("Code Invalid");
    HotspotLock.ResetCode();
  }
  else {
    // eCodeNoCode, so do nothing. 
  }


HotspotLock.ResetCode():

Again, self explanatory. Resets the entered code, and clears the 'display' objects.




Thanks to:
Chris Jones (obviously),
Maverick (for the original idea),
SSH (for his Combination Lock Module - http://www.bigbluecup.com/yabb/index.php?topic=23566.0 - which this is loosely based on),
you (for your interest.

Any questions, comments or suggestions can be PM'd to me (Ashen) via the aGS forums, or e-mailed to WhoIsMonkey@yahoo.com.
