Re: keypad Logic
Posted by KoopaTroopa on
Mon Jul 30th 2007 at 4:00pm
18 posts
2 snarkmarks
Registered:
Jul 18th 2007
I want to make a puzzle that consists of nothing more than a keypad who's keys light up when pressed and cease to light up when pressed again. For this question, let's keep it simple and say there are only 9 keys on the pad, arranged in a square. What I would like to have happen is for the player to see a shape above the keypad, say a T shape, and to be able to make that shape on the pad by toggling the different keys on or off. When the shape is made, the door opens or whatever.
I tried to do it with a counter, thinking that if I have the correct keys each add 1 and all the rest subtract 1, then the counter would only reach the right number when the right keys were pressed.
I ran into several problems however.
1) Getting the keys to stay in the "pressed" position but be able to be hit again to be unpressed. Not sure how to do this.
2) Getting the keys to do one thing (add 1) when pressed once and therefore activated, and then something else (subtract one) when pressed again and deactivated.
I hope I've made this clear enough. I do have a bit of programming background, so I know that what I really am looking for is an AND statement that is only activated if the right keys are pressed and the right keys are not.
Any ideas?
Re: keypad Logic
Posted by fishy on
Mon Jul 30th 2007 at 6:06pm
fishy
member
2623 posts
1476 snarkmarks
Registered:
Sep 7th 2003
Location: glasgow
In the "T" example, wouldn't it come up with the right number once any 5 buttons were pressed?
i eat paint
Re: keypad Logic
Posted by KoopaTroopa on
Mon Jul 30th 2007 at 6:16pm
18 posts
2 snarkmarks
Registered:
Jul 18th 2007
Stadric:
Ok. That makes sense, but I can't seem to be able to make the button stay in and then remain usable so that the player can hit it again and it will pop back out. It can't toggle. I'm thinking that I could do it by making a tiny func_tracktrain that would move back and forth to represent the button, and making a nodraw button for the real one that would do the actual work. This would be a bit more messy, but I think it would work. I would still have to find some way to make the real button toggle between add and subtract though.
Fishy:
No, because the keys that were supposed to not be pressed would actually subtract from the counter. Thus the only way the counter could ever reach the maxlimit would be if all the good keys were pressed and none of the bad ones.
Re: keypad Logic
Posted by Cash Car Star on
Mon Jul 30th 2007 at 9:02pm
1260 posts
345 snarkmarks
Registered:
Apr 7th 2002
Occupation: post-student
Location: Connecticut (sigh)
Use binary:
Key 1 = 1
Key 2 = 2
Key 3 = 4
Key 4 = 8
...
Key 9 = 512
If they're pressed they add to the counter, if not pressed, they are
worth zero. This way, every unique configuration of buttons
pressed results in a unique corresponding value.
Re: keypad Logic
Posted by KoopaTroopa on
Tue Jul 31st 2007 at 1:51pm
18 posts
2 snarkmarks
Registered:
Jul 18th 2007
OK, that's a good idea CCS. I do still have the problem of how to make the buttons work as input toggles.
As a work around I did get a system to work using func_movelinear 's that had two buttons for each. One button was parented to the func_movelinear and the other was not. Thus, when the fml was in the open position, the "to close" button is in front and the "to open" button is deactivated. Conversely when the fml moves to closed position, the "to close" button goes with it and is deactivated. This leaves the "to open" button active and in front.
It seems a bit complicated to explain but it's just a func_movelinear and two buttons with nodraw.
Re: keypad Logic
Posted by quanta on
Tue Aug 7th 2007 at 6:37pm
quanta
member
33 posts
53 snarkmarks
Registered:
Jun 14th 2007
Occupation: Student/Programmer
Location: USA
What if for each button there was a logic_relay that was toggled everytime the button was pressed? This would eliminate the need for func_movelinears or more than 9 buttons.
So each button will toggle a corresponding logic_relay, eliminating the need for the buttons to be toggled. Then have each button trigger another logic_relay after about 0.1 seconds, which will then trigger all the other logic_relays. Then using CCS's idea, reset the counter everytime a button is pressed, and when a button relay is triggered, add the corresponding value to the counter. After about 0.2 seconds, compare the value and get the result (using a logic_compare).
Let me know if you need any clarification or examples on this.
People its snarkpit.net not snarkpit.com! Be sure to check this when you add links!