Page 1 of 1
Pushing a Button Multiple Times
Posted: Thu Feb 14, 2013 3:19 am
by Grimfan
Hi everyone,
Is it possible to script a puzzle in which a single button needs to be pushed a certain number of times before it opens a door, destroys or spawns an object? it falls just outside my current scripting experience

and I'm not sure where to look for the answer if this has already been done.
And thanks in advance.

Re: Pushing a Button Multiple Times
Posted: Thu Feb 14, 2013 4:09 am
by Komag
You can script it without too much trouble, but in this case it's probably easiest to simply use a counter set to the number of times you want the button pushed, link the button to the counter with "decrement" and have the counter link to whatever you want to happen when the counter reaches 0 and activates
Re: Pushing a Button Multiple Times
Posted: Thu Feb 14, 2013 4:39 am
by Grimfan
*Forehead slap*
Thanks again Komag. I completely forgot about counters.
Re: Pushing a Button Multiple Times
Posted: Thu Feb 14, 2013 12:49 pm
by Grimwold
The trouble with using a counter in this way is that the player could simply spam the button until the door opened and not need to know exactly how many times to push the button.
If you didn't want that to happen you could perhaps have the counter count up and use a timer for a very short delay, after which it would check the value of the counter.. if it matched the predetermined value, the door would open. If it was higher then the puzzle would reset.
so each button push would
* increase the counter
* reset and start the timer
the timer would
* trigger a script to check the counter value
Re: Pushing a Button Multiple Times
Posted: Thu Feb 14, 2013 4:08 pm
by Grimfan
Grimwold wrote:The trouble with using a counter in this way is that the player could simply spam the button until the door opened and not need to know exactly how many times to push the button.
If you didn't want that to happen you could perhaps have the counter count up and use a timer for a very short delay, after which it would check the value of the counter.. if it matched the predetermined value, the door would open. If it was higher or lower then the puzzle would reset.
so each button push would
* increase the counter
* reset and start the timer
the timer would
* trigger a script to check the counter value
Thanks for the input Grimwold.
Since I want to make the button be pressed a set number of times for a door to open would it be simpler to use a timer, counter and script combination (as you have suggested) or just have a script cover the entire thing? I'm also assuming that the player would need to press the button the precise number of times and couldn't press over the amount? So if he needed to press the button six times but pressed it seven the door (or whatever) would stay closed with this sort of script/timer/counter combo?
Re: Pushing a Button Multiple Times
Posted: Thu Feb 14, 2013 4:12 pm
by Komag
You could have the player do something else after the button presses, like pull a lever, and that would check if the number is right
Re: Pushing a Button Multiple Times
Posted: Fri Feb 15, 2013 12:21 pm
by Grimwold
You could certainly do away with the counter and use a 'global' variable within your script entity to store the number of pushes... I suggested the timer to try and prevent player button spamming (i.e. pressing more times than required)... if you wanted to do it without a timer, you'd probably want a lever or plate (or button) to check the number is right, as Komag suggested.
As an aside, you could use my "Generic Button/Lever Combination Script" -
viewtopic.php?f=14&t=4461
And simply list the same button as many times as you required.. after all it's just a 1 button combination. I just tested this and it worked quite well, but with the button too close to the door it was obvious that the Xth push opened it, and then the X+1th push closed it and reset the puzzle. An alternative would be 2 buttons (similar to Komag's suggestion)... x pushes of button_1 followed by 1 push of button_2... and make it obvious to the player that button 2 checks the quantity of pushes to button 1.
Re: Pushing a Button Multiple Times
Posted: Fri Feb 15, 2013 12:22 pm
by Conchron
Grimwold wrote:The trouble with using a counter in this way is that the player could simply spam the button until the door opened and not need to know exactly how many times to push the button.
Your solution is so clever!
Me, I'm not so smart and I "solved" it by spawning fireballs of doom if the button is spammed.

Re: Pushing a Button Multiple Times
Posted: Fri Feb 15, 2013 5:22 pm
by Grimfan
Funnily enough I didn't end up going with a script or timer but just used Komag's initial suggestion. I already have three scripts running in the same area and didn't want to make it even more congested by adding yet another script. Thanks for pointing out the alternatives however, as I'm sure they will come in handy in the future (possibly even in the same mod).
