Double-Locked Door?
182crazyking
28 Aug 2012, 04:41Hey guys, real speedy question here. How would I create a door that requires two parameters to unlock?
Here's the scenario: I have a room (D5 Door Gate) that has a locked exit (D5_Door) to a second room (D5 Entrance Corridor).
The player needs to swipe two keycards (Access Cards 1 and 2, respectively) into their respective readers (Readers 1 and 2, respectively). That then opens the door.
Now, what I have now is a script that goes like this (sorry about not posting the actual core script; I don't know how to get it from the editor):
The reason I used the objects dummy_gate_1 and _2 (Invisible objects) is because I don't want crafty players bypassing the key card hunt by just saying "switch on Reader 1." There's probably a way to fix that, which would be nice to know.
Also, by using the two "If" scripts in a row, I was basically trying to make an "and" gate. Is there a way to do this that works?
Cheers, guys!
Here's the scenario: I have a room (D5 Door Gate) that has a locked exit (D5_Door) to a second room (D5 Entrance Corridor).
The player needs to swipe two keycards (Access Cards 1 and 2, respectively) into their respective readers (Readers 1 and 2, respectively). That then opens the door.
Now, what I have now is a script that goes like this (sorry about not posting the actual core script; I don't know how to get it from the editor):
Use (Access Card 1) on (Reader 1)
Print "You swipe the card, and a light on the machine turns green." / Switch on dummy_gate_1
Use (Access Card 2) on (Reader 2)
Print "You swipe the card, and a light on the machine turns green." / Switch on summy_gate_2
After switching on dummy_gate_1
If: Object is switched on (object: dummy_gate_1)
Then:
If: Object is switched on (object: dummy_gate_2)
Then:
Print "The door slowly rises."
Unlock exit (exit: D5_door)
The reason I used the objects dummy_gate_1 and _2 (Invisible objects) is because I don't want crafty players bypassing the key card hunt by just saying "switch on Reader 1." There's probably a way to fix that, which would be nice to know.
Also, by using the two "If" scripts in a row, I was basically trying to make an "and" gate. Is there a way to do this that works?
Cheers, guys!
sgreig
28 Aug 2012, 07:57Does that script you have not work? Or are you just looking for alternative ways to accomplish what you're talking about?
The way I would approach something like this would be to put a flag on each of the readers. So when you use the respective card on each reader, I would put something like this in the script:
Reader 1:
Reader 2:
This way it doesn't matter in which order you swipe the cards, the door will still open. If you want them to have to be swiped in a specific order, the script would be fairly easy to modify for that. Also, using this method you don't have to create invisible dummy objects.
The way I would approach something like this would be to put a flag on each of the readers. So when you use the respective card on each reader, I would put something like this in the script:
Reader 1:
if (reader1.flag = true) {
if (reader2.flag = true) {
msg ("The door slowly rises.")
UnlockExit (D5_door)
}
}
else {
msg ("You swipe the card, and a light on the machine turns green.")
reader1.flag = true
}
Reader 2:
if (reader2.flag = true) {
if (reader1.flag = true) {
msg ("The door slowly rises.")
UnlockExit (D5_door)
}
}
else {
msg ("You swipe the card, and a light on the machine turns green.")
reader2.flag = true
}
This way it doesn't matter in which order you swipe the cards, the door will still open. If you want them to have to be swiped in a specific order, the script would be fairly easy to modify for that. Also, using this method you don't have to create invisible dummy objects.

182crazyking
28 Aug 2012, 14:09sgreig wrote:Does that script you have not work? Or are you just looking for alternative ways to accomplish what you're talking about?
It doesn't; I swipe both readers and the script doesn't run.
sgreig wrote:The way I would approach something like this would be to put a flag on each of the readers. So when you use the respective card on each reader, I would put something like this in the script:
--snip--
This way it doesn't matter in which order you swipe the cards, the door will still open. If you want them to have to be swiped in a specific order, the script would be fairly easy to modify for that. Also, using this method you don't have to create invisible dummy objects.
Oh, nice, I'll try that once I get home from school. I kinda thought that my method of using two "If:"s in a row to create an "and" gate screwed up the code. Guess not. Cheers, mate!


Pertex
28 Aug 2012, 14:47You can do it with "and" but then you have to type the scriptexpression:


sgreig
28 Aug 2012, 20:47Pertex wrote:You can do it with "and" but then you have to type the scriptexpression:
if.jpg
Or in the case of my code example, I guess it would be:
if (reader1.flag = true) and (reader2.flag = true) {
msg ("The door slowly slides open.")
UnlockExit (D5_door)
}
else {
reader1.flag = true
}
and the same for reader 2, but change the else part to "reader2.flag = true". Pertex's suggestion will work as well, but it still requires you to use the two invisible dummy objects, which is really not necessary.

182crazyking
29 Aug 2012, 00:12Alrighty! I'm back from trying pretty much everything ever. What I ended up with was (non-standard code because I still can't figure out how to get that code that you guys have, short of writing it manually) :
And pretty much the same thing for Reader 2. After swiping the respective cards, I got two consecutive "A light on the machine turns green." messages, but nothing happened. Then I realized that I had to swipe a card on it's reader once more so that it would preform the check to see if both objects have a flag again.
I'm gonna cheat my way out of this by adding a button to press when both readers are active that runs the check. So consider my problem effectively solved! Thanks, both of you!
If: object has flag | object | reader1 | flag name | true
then:
If: object has flag | object | reader2 | flag name | true
then:
Print: message | The door slowly rises.
Unlock exit | exit | D5_door
Else:
Print: message | A light on the machine turns green.
Set flag | object | reader1 | flag name | true
And pretty much the same thing for Reader 2. After swiping the respective cards, I got two consecutive "A light on the machine turns green." messages, but nothing happened. Then I realized that I had to swipe a card on it's reader once more so that it would preform the check to see if both objects have a flag again.
I'm gonna cheat my way out of this by adding a button to press when both readers are active that runs the check. So consider my problem effectively solved! Thanks, both of you!
