Page 1 of 2

[Help] Scripting a combination lock with buttons.

Posted: Wed Sep 12, 2012 5:33 pm
by Arrkangel
First of all this editor is awesome. So user friendly and clean.
Ill be here for days..ha

I have read up on the modding tutorials on scripting a combination lock for levers and done that and had no problems. I then tried with buttons and i came into a few problems. I tried reading the Scripting Reference too but i seem to be doing something wrong.

i suppose not being that good at scripting does hinder me, any suggestions?

Re: [Help] Scripting a combination lock with buttons.

Posted: Wed Sep 12, 2012 7:16 pm
by cromcrom
What about describing your problems ?

Re: [Help] Scripting a combination lock with buttons.

Posted: Wed Sep 12, 2012 8:09 pm
by Komag
There is no getButtonState on the scripting reference list, so I'm not sure it will work like that. I did something similar with pressure plates, but had to use an extra step to transition it to levers:
viewtopic.php?f=14&t=3032

Re: [Help] Scripting a combination lock with buttons.

Posted: Wed Sep 12, 2012 8:13 pm
by petri
Komag wrote:There is no getButtonState on the scripting reference list, so I'm not sure it will work like that. I did something similar with pressure plates, but had to use an extra step to transition it to levers:
viewtopic.php?f=14&t=3032
Buttons have no state. They simply activate when they're pressed.

Re: [Help] Scripting a combination lock with buttons.

Posted: Wed Sep 12, 2012 8:33 pm
by Komag
Ah yes, that makes sense!

Re: [Help] Scripting a combination lock with buttons.

Posted: Wed Sep 12, 2012 8:37 pm
by Magus
You need to store the pressed button with a variable because buttons don't have on/off states

Re: [Help] Scripting a combination lock with buttons.

Posted: Fri Oct 12, 2012 10:22 am
by Custode
I have found a way to do it, it is a little laborious but it works.
I am not completely sure if this is already been done, if not let me know and I will write the process and show a little example with three buttons as a starting point.

Re: [Help] Scripting a combination lock with buttons.

Posted: Fri Oct 12, 2012 11:59 am
by Grimwold
A relatively simple way to do it, should be to have a counter for each button and a script to check the values of the counters.

Each time a button is pressed its associated counter would be incremented. There'd also be a check values button to test the combination... if checking was done every time a button was pressed you would get a situation where you could spam the final button until you got the right value. The check values button would double as a reset for the counters back to their starting values in case of failure.

Re: [Help] Scripting a combination lock with buttons.

Posted: Fri Oct 12, 2012 12:21 pm
by Custode
Grimwold wrote:A relatively simple way to do it, should be to have a counter for each button and a script to check the values of the counters.

Each time a button is pressed its associated counter would be incremented and the script would check the values... if all counters had their respective correct values the script would open a door... You'd also need a reset button to set all counters back to their starting values in case of failure.
I guess there are multiple ways to achieve the same or similar results, anyway in my case there is no need for a reset button, when the correct combination is given the script opens the door otherwise it remains closed and you can keep pushing the buttons how many times you like.
Anyway, I have not seen any other discussion about this and I thought it was still unused due to some "limitation" of the editor, should I post my solution? I esitate because I don't want to write something that maybe is already well known.

Re: [Help] Scripting a combination lock with buttons.

Posted: Fri Oct 12, 2012 1:00 pm
by Grimwold
I'd go ahead and post your solution anyway... Many of the threads here have multiple ways to do things.