3 Checkers / Buttons Problem

Avatar
Logic
298 Posts
Posted Apr 30, 2012
Probably an easy question but I can't quite figure it out.

img

So I have 3 checkers on the wall. I also have 3 buttons in the level. I want a connection that does the following:

  • When 1 button is pressed down the first one light up
  • When 2 buttons are pressed down the first 2 light up
  • When 3 buttons are pressed down all 3 light up

Notice that it doesn't matter which one of the buttons gets pressed down, the order should still be the same.

I know how a math_counter works and tried to make the connection that way. But I couldn't quite figure it out.

Is there a simple way to make this connection?

Advertisement
Registered users don’t see ads! Register now!
Avatar
josepezdj
2,386 Posts
Posted Apr 30, 2012
Replied 33 minutes later
The best way for such a setting is to use logic_branch entities (one per button) plus a logic_branch_listener entity per checker.

Then in the buttons relays (I'm assuming you use a couple of logic_relay entities per button), you have to set them this way:

"relay ON" = on button pressed > logic_branch > SetValue > 1
"relay OFF" = on button pressed > logic_branch > SetValue > 0

Then in the loggic_branch_listener you have to set it for the different cases:

On ALL true (this means that ALL buttons are pressed) > whatever
On ALL false (none of them are pressed) > whatever
On Mixed > whatever

It's that simple. Read about such those 2 entities and check if you can manage to ddo it yourself. Otherwise tell in this thread and I'll be more specific...

Avatar
Logic
298 Posts
Posted Apr 30, 2012
Replied 13 minutes later

josepezdj wrote:
The best way for such a setting is to use logic_branch entities (one per button) plus a logic_branch_listener entity per checker.

Then in the buttons relays (I'm assuming you use a couple of logic_relay entities per button), you have to set them this way:

"relay ON" = on button pressed > logic_branch > SetValue > 1
"relay OFF" = on button pressed > logic_branch > SetValue > 0

Then in the loggic_branch_listener you have to set it for the different cases:

On ALL true (this means that ALL buttons are pressed) > whatever
On ALL false (none of them are pressed) > whatever
On Mixed > whatever

It's that simple. Read about such those 2 entities and check if you can manage to ddo it yourself. Otherwise tell in this thread and I'll be more specific...

Thanks. This is probably the way to go. But I still can't seem to get it right.

As you said there are 3 ways to send out a signal:
- On all true
- On all false
- On Mixed

But that is only 3 signals and I need 4:
- No buttons are pressed
- One button is pressed
- Two buttons are pressed
- All three buttons are pressed

I can't seem to find a way to do this since there are only 3 options :/

Avatar
RustyDios
154 Posts
Posted Apr 30, 2012
Replied 14 minutes later
Try using three math_counters ... each called the same... but the max value one higher on each one... have the outputs of the buttons to add/subtract to the math_counters on pressed/unpressed... and each separate counter to have activate a different checkbox.... thus when the math = 0 all checkboxes are off.. when math = 1, counter one hits max value and lights checkbox one..... when math = 2, counter two hits max and checkbox two lights.... and when math = 3, counter three hits max and lights checkbox three.... .... on button unpressed the math is lowered by one so you want the lower legal-value to be one lower then the max number for that counter.. but you want the starting number for all three to be the same (ie 0).... ...

Hope that makes sense, I know this works as I've just done a very similar thing in my map with a "chain of indicator lights" working with several "relay buttons".... ...

Avatar
Logic
298 Posts
Posted Apr 30, 2012
Replied 10 minutes later

RustyDios wrote:
Try using three math_counters ... each called the same... but the max value one higher on each one... have the outputs of the buttons to add/subtract to the math_counters on pressed/unpressed... and each separate counter to have activate a different checkbox.... thus when the math = 0 all checkboxes are off.. when math = 1, counter one hits max value and lights checkbox one..... when math = 2, counter two hits max and checkbox two lights.... and when math = 3, counter three hits max and lights checkbox three.... .... on button unpressed the math is lowered by one so you want the lower legal-value to be one lower then the max number for that counter.. but you want the starting number for all three to be the same (ie 0).... ...

Hope that makes sense, I know this works as I've just done a very similar thing in my map with a "chain of indicator lights" working with several "relay buttons".... ...

I did that when I tried it myself. It dosn't work since Math_Counters wont go any higher than the MAX-value (I think).

I recreated this exacts setup just now. It works when you put the cubes onto the buttons, but not when you take them off. 2 or even 3 checkers can be put out at once by removing one cube with this setup :/

But you said that it worked? How? :O

Avatar
Brainstone
401 Posts
Posted Apr 30, 2012
Replied 1 hour later
Here's a complex logical slution. I'm not in university yet, and maybe someone who studied Informatics knows a very better solution, but here is my solution:

Each Button has its own logic_branch (branch_1/2/3).
There is one branch_help.

branch_listener_main listens to all three branches.
On all true --> branch_help: set to 1. Turn all three lamps on.
On all false --> branch_help: set to 1. Turn all three lamps out.
On mixed --> branch_help: set to 0. Turn the first two lamps on, the third out.

Three branch_listener_help listen each to two of the branches1-3, aswell as to the branch help. They all have the same output:
On all false --> Turn lamp 2 out.

I believe this should work. I hope I haven't made a logical mistake somewhere.

EDIT: This one is without the lamp 2 flickering, almost the same:

Each Button has its own logic_branch (branch_1/2/3).
There is one branch_help.

branch_listener_main listens to all three branches.
On all true --> branch_help: set to 0. Turn all three lamps on.
On all false --> branch_help: set to 0. Turn all three lamps out.
On mixed --> branch_help: set to 1. Turn the first lamp on, the second and third out.

Three branch_listener_help listen each to two of the branches1-3, aswell as to the branch help. They all have the same output:
On all true --> Turn lamp 2 on.

Avatar
Logic
298 Posts
Posted Apr 30, 2012
Replied 2 hours later

Brainstone wrote:
Here's a complex logical slution. I'm not in university yet, and maybe someone who studied Informatics knows a very better solution, but here is my solution:

Each Button has its own logic_branch (branch_1/2/3).
There is one branch_help.

branch_listener_main listens to all three branches.
On all true --> branch_help: set to 1. Turn all three lamps on.
On all false --> branch_help: set to 1. Turn all three lamps out.
On mixed --> branch_help: set to 0. Turn the first two lamps on, the third out.

Three branch_listener_help listen each to two of the branches1-3, aswell as to the branch help. They all have the same output:
On all false --> Turn lamp 2 out.

I believe this should work. I hope I haven't made a logical mistake somewhere.

EDIT: This one is without the lamp 2 flickering, almost the same:

Each Button has its own logic_branch (branch_1/2/3).
There is one branch_help.

branch_listener_main listens to all three branches.
On all true --> branch_help: set to 0. Turn all three lamps on.
On all false --> branch_help: set to 0. Turn all three lamps out.
On mixed --> branch_help: set to 1. Turn the first lamp on, the second and third out.

Three branch_listener_help listen each to two of the branches1-3, aswell as to the branch help. They all have the same output:
On all true --> Turn lamp 2 on.

Sounded good. I'll give it a shot tomorrow :smile:

Avatar
josepezdj
2,386 Posts
Posted Apr 30, 2012
Replied 44 minutes later

Logic wrote:
But that is only 3 signals and I need 4:
- No buttons are pressed
- One button is pressed
- Two buttons are pressed
- All three buttons are pressed

I can't seem to find a way to do this since there are only 3 options :/

OK, first of all, there are 3 possibilities but you have to set those for EACH of your 3 cases. You must set 1 logic_branch entity for each button (call them button1_branch, button2_branch/ etc.), total 6, ok? and 2 logic_relays (call them for instance button1_relay_ON / button1_relay_OFF, etc.) for each button as well, total 12, ok? And finally 1 branch_listener PER CASE... Then each button settings will be as follows:

***OnButtonPressed > button_relay_ON > trigger
OnUnPressed > button_relay_OFF > trigger ***

The logic_relay_ON will be set as follows:

OnTrigger > logic_relay_OFF > CancelPending / delay 0:00
OnTrigger > button1_branch > SetValue > 1 / delay 0:20

The logic_relay_OFF will be set as follows:

OnTrigger > logic_relay_ON > CancelPending / delay 0:00
OnTrigger > button1_branch > SetValue > 0 / delay 0:20

Into each logic_branch_listener, you have to set which logic_branches it will "listen" (it will examine), ok? Let's see the more complex case of your 3 cases: three buttons (their names would be button4_branch / button5_branch and button6_branch) for 1 output (lights or whatever). Into the logic_branch_listener, you should set up the 3 logic_branches:

Logic Branch 1 = Button4_branch
Logic Branch 2 = Button5_branch
Logic Branch 3 = Button6_branch

Well, this is what you have to set in the logic_branch__listener outputs:

On ALL True > lights > Turn on (this means that ALL the 3 branches has emit a value of "1", ok?)
On ALL False > lights > Turn off (no branch has emitted a value of "1"m but of "0", that's to say "no button is pressed", ok?)
On Mixed > lights > Turn off (this means that even though 1 or 2 buttons are pressed we don't want the output to be fired, we want 3, so maybe some branch has emitted a value of "1", but IF there is at least one branch that emitted a value of "0", the output won't be fired, ok?)

I guess now it's clearer, right? I can extend myself even more, but I think you could now get it clear. Make some try and let us know if you got it, k?

Avatar
RustyDios
154 Posts
Posted Apr 30, 2012
Replied 20 minutes later

Logic wrote:
RustyDios wrote:

Try using three math_counters ... each called the same... but the max value one higher on each one... have the outputs of the buttons to add/subtract to the math_counters on pressed/unpressed... and each separate counter to have activate a different checkbox.... thus when the math = 0 all checkboxes are off.. when math = 1, counter one hits max value and lights checkbox one..... when math = 2, counter two hits max and checkbox two lights.... and when math = 3, counter three hits max and lights checkbox three.... .... on button unpressed the math is lowered by one so you want the lower legal-value to be one lower then the max number for that counter.. but you want the starting number for all three to be the same (ie 0).... ...

Hope that makes sense, I know this works as I've just done a very similar thing in my map with a "chain of indicator lights" working with several "relay buttons".... ...

I did that when I tried it myself. It dosn't work since Math_Counters wont go any higher than the MAX-value (I think).

I recreated this exacts setup just now. It works when you put the cubes onto the buttons, but not when you take them off. 2 or even 3 checkers can be put out at once by removing one cube with this setup :/

But you said that it worked? How? :O

Okay I'd not had this happen with my indicator lights setup and the texture_toggles... but after you mentioned it, I went and tried to recreate it....took me an hour but you are correct.... sorry, more testing on my part needed before spouting a "solution". I should stop trying to be helpful on the forums I think until I know for sure what I'm doing!!....

Looks like I'll be trying out the above tonight too :smile:

Avatar
Logic
298 Posts
Posted May 01, 2012
Replied 11 hours later

Brainstone wrote:
LETS SAVE SOME SPACE :wink:
||Here's a complex logical slution. I'm not in university yet, and maybe someone who studied Informatics knows a very better solution, but here is my solution:

Each Button has its own logic_branch (branch_1/2/3).
There is one branch_help.

branch_listener_main listens to all three branches.
On all true --> branch_help: set to 1. Turn all three lamps on.
On all false --> branch_help: set to 1. Turn all three lamps out.
On mixed --> branch_help: set to 0. Turn the first two lamps on, the third out.

Three branch_listener_help listen each to two of the branches1-3, aswell as to the branch help. They all have the same output:
On all false --> Turn lamp 2 out.

I believe this should work. I hope I haven't made a logical mistake somewhere.

EDIT: This one is without the lamp 2 flickering, almost the same:

Each Button has its own logic_branch (branch_1/2/3).
There is one branch_help.

branch_listener_main listens to all three branches.
On all true --> branch_help: set to 0. Turn all three lamps on.
On all false --> branch_help: set to 0. Turn all three lamps out.
On mixed --> branch_help: set to 1. Turn the first lamp on, the second and third out.

Three branch_listener_help listen each to two of the branches1-3, aswell as to the branch help. They all have the same output:
On all true --> Turn lamp 2 on.||

I think that I've done everything right but this one doesn't seem to work. There is a glitch where if you place 2 buttons and then remove one, the second light is still checked.

Never through there was going to be such a hassle to get this done xD

Avatar
josepezdj
2,386 Posts
Posted May 01, 2012
Replied 16 minutes later
Logic, did you read my latest reply above and try it THAT way?

http://forums.thinking.withportals.com/post72282.html#p72282

Avatar
Logic
298 Posts
Posted May 01, 2012
Replied 9 minutes later

josepezdj wrote:
Logic, did you read my latest reply above and try it THAT way?

http://forums.thinking.withportals.com/post72282.html#p72282

Haven't had the time for that one yet. I'll try it later on tonight :smile:

Avatar
Brainstone
401 Posts
Posted May 01, 2012
Replied 1 hour later
OK, my sooner solution doesn't seem to work, because a branch_listener doesn't seem to generate the onMixed Output when it changes from Mixed to Mixed. Darn. But maybe you don't need such a complicated solution like josepezdj's. I have another shorter idea:

Two Math_counters: CounterA and CounterB
Each button influences both CounterA and B (+1 when pressed, -1 when unpressed)
CounterA has 2 as maximum value. CounterB has 3 as maximum value.

Now the trick:
CounterB --> OnChangedfromMax --> Set Value of CounterA to 2. (Do generate Output on Value)
You can do this maybe with a slight delay of 0.01, but I don't think this should be necessary.

The rest is easy:
CounterA controls the lamp states from 0 to 2:
OnHitMin: lamp 1 out
OnChangedFromMin: lamp 1 on
OnChnagedFromMax: lamp 2 out
OnHitMax: lamp 2 on

CounterB controls the last lamp state:
OnHitMax: lamp 3 on
OnChangedFromMax: lamp 3 out
OnChangedFromMax: CounterA SetValue 2 (Do generate output OutValue; Delay: 0)

EDIT: I've just tested this out. It works flawless!!!!!
:cool: :cool: :cool:

Avatar
Logic
298 Posts
Posted May 01, 2012
Replied 46 minutes later

Brainstone wrote:
OK, my sooner solution doesn't seem to work, because a branch_listener doesn't seem to generate the onMixed Output when it changes from Mixed to Mixed. Darn. But maybe you don't need such a complicated solution like josepezdj's. I have another shorter idea:

Two Math_counters: CounterA and CounterB
Each button influences both CounterA and B (+1 when pressed, -1 when unpressed)
CounterA has 2 as maximum value. CounterB has 3 as maximum value.

Now the trick:
CounterB --> OnChangedfromMax --> Set Value of CounterA to 2. (Do generate Output on Value)
You can do this maybe with a slight delay of 0.01, but I don't think this should be necessary.

The rest is easy:
CounterA controls the lamp states from 0 to 2:
OnHitMin: lamp 1 out
OnChangedFromMin: lamp 1 on
OnChnagedFromMax: lamp 2 out
OnHitMax: lamp 2 on

CounterB controls the last lamp state:
OnHitMax: lamp 3 on
OnChangedFromMax: lamp 3 out
OnChangedFromMax: CounterA SetValue 2 (Do generate output OutValue; Delay: 0)

EDIT: I've just tested this out. It works flawless!!!!!
:cool: :cool: :cool:

I was just about to quote you on that and tell you that it doesn't work. Saw the new text when I wrote my own response xD

It works great! I missed the part with the Set Value at the second counter, but I've tried every single configuration now and it doesn't glitch :biggrin:

Thanks for your help. You'll see your counter in an upcoming map :wink:

Sorry josepezdj, but this solution seemed way easier than using branches, so I just had to try it out :razz:

Avatar
HMW
806 Posts
Posted May 01, 2012
Replied 3 hours later
I know this is already solved, but I just wanted to throw my solution out there in case anyone ever needs to do this with more than three buttons; see attachment.

(Though I must admit that the 2-counter method is very elegant and uses fewer entities.)

Avatar
Idolon
417 Posts
Posted May 01, 2012
Replied 9 hours later
I personally would hook up a math_counter's InValue to a logic_case. It uses only 2 entities, and can be applied to up to 16 buttons. The only problem is that you will end up with n^2 outputs for the logic_case, where n is your number of buttons. Having more than 4 buttons will be very, very messy.
Advertisement
Registered users don’t see ads! Register now!
Avatar
RustyDios
154 Posts
Posted May 02, 2012
Replied 13 hours later

HMW wrote:
I know this is already solved, but I just wanted to throw my solution out there in case anyone ever needs to do this with more than three buttons; see attachment.

Thanking you kindly, the entire logic of one chamber in my map just got replaced. :smile: Noting you down for inclusion into the credit list :smile:

And again for good measure, Thankyou.