Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Candle on Wed 16/11/2005 08:10:29

Title: I need help programmin a combination lock (keypad)
Post by: Candle on Wed 16/11/2005 08:10:29
I want to have this lock open when the right numbers are press.
And I suck at doing variables and the stuff.
I just get lost now trying to make heads and tails of it .
I have it now where you click one number and it turns on a hotspot and so forth but thats not the right way to do it I'm sure.
I like to do this stuff myself but I think I'm going to ask if someone can code this for me . I don't care what numbers end up opening the door .
Just so I can get it to work.
Feel like taking pitty on a dumbshit.

(http://img158.imageshack.us/img158/3900/dial7mw.jpg)
Title: Re: I need help programmin a dial lock
Post by: Elliott Hird on Wed 16/11/2005 10:25:49
I'll help. PM me ;).
Title: Re: I need help programmin a dial lock
Post by: Ashen on Wed 16/11/2005 11:30:33
Thi shas been asked quite a few times before - although it is a little difficult to know exactly what to search for. This thread (http://www.adventuregamestudio.co.uk/yabb/index.php?topic=13771.0) shows the basic way to do it (two ways, actually - hotspots or a GUI). Or, this one (http://www.adventuregamestudio.co.uk/yabb/index.php?topic=8231.0) has a few other suggestions. (Keep in mind, some of the code won't be directly compatable with newer versions of AGS.)

Elliott:
How about posing your isead, for anyone else who needs it?
Title: Re: I need help programmin a dial lock
Post by: Elliott Hird on Wed 16/11/2005 11:57:23
Ashen, Normally I like to co-ordinate my code through PM so I'm certain that's what they want, then I post it here.
Title: Re: I need help programmin a dial lock
Post by: esper on Wed 16/11/2005 11:58:51
This is what I came up with for a non-code solution.

http://www.adventuregamestudio.co.uk/yabb/index.php?topic=22843.msg281195#msg281195

Yes, I was mean to the poor Russian newb, but I apologised in the end... And it worked for him, so....
Title: Re: I need help programmin a combination lock (keypad)
Post by: SSH on Wed 16/11/2005 12:06:31
I've added this to my list of modules in the Tech forum, as I'm sure someone coudl do a generic version of this.
Title: Re: I need help programmin a combination lock (keypad)
Post by: Candle on Wed 16/11/2005 19:07:40
Thank you I will look at that post with the code when I wake up here.
Looks like it would do ths trick esper.
Title: Re: I need help programmin a combination lock (keypad)
Post by: Candle on Wed 16/11/2005 20:55:04
I was look at the one link that Ashen gave and found this and I have it working but wanted to know how to change the numbers it uses?
Ok, here it is, step by step:

- Go to Room Editor / Settings
- Press the button labelled "{ }"
- Put this in there:
Ã,  Ã, int sequence=0;
- Close the window (and tell it to save)

The following you have to do for each of the 4 hotspots:

- Go to "Room Editor" / "Areas" and select "Hotspots" from the drop-down menu
- Select the hotspot
- Press the button labelled "Interaction..."
- Double-click on "Interact with hotspot"
- Select "Run script" from the drop-down menu
- Press the "Edit script..." button

- Put this in hotspot 1:
Ã,  Ã, if (sequence == 0) sequence++;
Ã,  Ã, else sequence = 0; // wrong combination, so start again

- If you are editing hotspot 2, put this in there:
Ã,  Ã, if (sequence == 1) sequence++;
Ã,  Ã, else sequence = 0; // wrong combination, so start again

- This in hotspot 3:
Ã,  Ã, if (sequence == 2) sequence++;
Ã,  Ã, else sequence = 0; // wrong combination, so start again

- And this in hotspot 4:
Ã,  Ã, if (sequence == 3) { // correct combination so
Ã,  Ã,  Ã,  AddInventory(5); // give player the ice cream
Ã,  Ã, }
Ã,  Ã, else sequence = 0; // wrong combination, so start again

- Exit and save

So would I change the numbers to what I want it to be to open the lock.I have 10 numbers but don't plan oin using them all.
sorry for being so dumb today .
I just can't get mind right .
Title: Re: I need help programmin a combination lock (keypad)
Post by: Ashen on Wed 16/11/2005 21:07:25
Yes, just change the numbers, so if you wanted the code to be 9362 it'd be like above, but:

- Put this in hotspot 9:
   if (sequence == 0) sequence++;
   else sequence = 0; // wrong combination, so start again

- This in hotspot 3:
   if (sequence == 1) sequence++;
   else sequence = 0; // wrong combination, so start again

- This in hotspot 6:
   if (sequence == 2) sequence++;
   else sequence = 0; // wrong combination, so start again

- And this in hotspot 2:
   if (sequence == 3) { // correct combination so
      AddInventory(5); // give player the ice cream
   }
   else sequence = 0; // wrong combination, so start again

And, you'd probably want the hotspots for the other keys - 1, 4, 5, 7, 8, 10 (for 0) - to all have:

sequence = 0; // wrong combination, so start again

(So that, for example, 9-3-6-4-2 wouldn't work.)
Title: Re: I need help programmin a combination lock (keypad)
Post by: Candle on Wed 16/11/2005 21:13:55
Thank you . I can get it working now .
Thanks again.