If's and Conditional Statements

Avatar
dhavalmistry
107 Posts
Posted Jun 04, 2011
How do I setup if or conditional statements in hammer? For example, if the laser_catcher is powered AND button IsPressed, then FireOutput. I found logic_multicompare and logic_compare but I am not sure how to compare.
Advertisement
Registered users don’t see ads! Register now!
Avatar
Fresh
17 Posts
Posted Jun 04, 2011
Replied 34 minutes later

Dont know much about them hopefully, these will help you

http://developer.valvesoftware.com/wiki/Logic_compare

http://developer.valvesoftware.com/wiki/Logic_gate

Avatar
Madk
15 Posts
Posted Jun 04, 2011
Replied 22 minutes later
I've always used overly intricate combinations of logic_relays by disabling and triggering them to produce logic functions.
Avatar
Croolsby
29 Posts
Posted Jun 04, 2011
Replied 28 minutes later
For this scenario, I would use logic_branch and logic_branch_listener.

outputs for catcher:
"OnPowered, Logic_branch_catcher, SetValue <1>"
"OnUnpowered, Logic_branch_catcher, SetValue <0>"
"OnPowered, logic_branch_listener, test"
"OnUnPowered, logic_branch_listener, test"

outputs for button:
"OnPressed, Logic_branch_button, SetValue <1>"
"OnUnpressed, Logic_branch_button, SetValue <0>"
"OnPressed, logic_branch_listener, test"
"OnUnPressed, logic_branch_listener, test"

Now set the branches the logic_branch_listener will listen to to be logic_branch_catcher and logic_branch_button.

outpus for logic_branch_listener:
"OnAllTrue, [target entity], [input]"

I think that should work. Let us know if it doesn't work.

Avatar
dhavalmistry
107 Posts
Posted Jun 04, 2011
Replied 35 minutes later

Croolsby wrote:
For this scenario, I would use logic_branch and logic_branch_listener.

outputs for catcher:
"OnPowered, Logic_branch_catcher, SetValue <1>"
"OnUnpowered, Logic_branch_catcher, SetValue <0>"
"OnPowered, logic_branch_listener, test"
"OnUnPowered, logic_branch_listener, test"

outputs for button:
"OnPressed, Logic_branch_button, SetValue <1>"
"OnUnpressed, Logic_branch_button, SetValue <0>"
"OnPressed, logic_branch_listener, test"
"OnUnPressed, logic_branch_listener, test"

Now set the branches the logic_branch_listener will listen to to be logic_branch_catcher and logic_branch_button.

outpus for logic_branch_listener:
"OnAllTrue, [target entity], [input]"

I think that should work. Let us know if it doesn't work.

That kinda makes sense (I am not a programmer). How would I go implementing this with a cube dropper and laser catcher.

If the laser catcher is powered AND the cube is fizzled, spawn another cube.

Avatar
yohoat9
274 Posts
Posted Jun 04, 2011
Replied 1 hour later
Just use a counter, have the target number as 2, and the initial number as 0. Have the button add 1 to the counter, and have the laser catcher do the same. Have them subtract 1 when they're deactivated.
Avatar
Supervillain
34 Posts
Posted Jun 04, 2011
Replied 30 minutes later

yohoat9 wrote:
Just use a counter, have the target number as 2, and the initial number as 0. Have the button add 1 to the counter, and have the laser catcher do the same. Have them subtract 1 when they're deactivated.

yah, I'm a big fan of counters. Manipulating them is very similar to some core tenants of programing.

Adding and subtracting from a counter, and having it fire an output on a certain number is an excellent way to get what you want.

This may not apply directly to your situation, but setting the counter to 1, and multiplying by -1 (say, on button pressed and button UnPressed) is a great way to create a toggle.

Avatar
dhavalmistry
107 Posts
Posted Jun 04, 2011
Replied 11 minutes later
I am lost :sad:
Avatar
yohoat9
274 Posts
Posted Jun 04, 2011
Replied 2 minutes later

Supervillain wrote:
This may not apply directly to your situation, but setting the counter to 1, and multiplying by -1 (say, on button pressed and button UnPressed) is a great way to create a toggle.

Yeah, I have a lot of experience with basic programing, I used to make so many games on my TI-83 calculator. I made an entire fully functional tic-tac-toe game, and you often had to multiply variables by negative one for alternating who's turn it was and stuff, (it had like 500 lines of code).

Avatar
Another Bad Pun
516 Posts
Posted Jun 04, 2011
Replied 47 minutes later

dhavalmistry wrote:
I am lost :sad:

Okay so lets say I wanted to open a door. But you need to press two buttons to open the door. When you press one of the two buttons, the counter thingy adds one plus zero which equals 1. So we pressed one button, but we need to press all two to make the door open. If we press the other button, it will fire an output and add one. ( In this case it would be 1+1=2) When the counter thingy reaches two, it fires an output and opens the door. If it's a cube button, you can add and subrtact one from the total amount. This tutorial dosen't use the same entitiy, but it uses it in a simaler way: (This is for Portal 1 BTW but it should still work for Portal 2.) http://developer.valvesoftware.com/wiki/Creating_multiple_buttons_for_one_door

EDIT: Aswering your question: when a cube is placed on the button, add one to the current number in the counter. WHen the laser catcher is activated, add one to the current number count. If you set the door, (or whatever you want to trigger,) to open ore activate when the timer reachse two, it will work. You should aslo set it to subtract one from the number count when the cube is taken off the button ore the laser catcher is deactivated. Basicly what Yohoat9 said about the problem.

Avatar
Idolon
417 Posts
Posted Jun 04, 2011
Replied 10 minutes later
Counters are great for case statements, by the way (limited to 4 different entities). In other words, you can have a different output for each possible situation of the on/off state of 4 different entities. Just have them add/subtract 1, 2, 4, or 8. Just use a logic_case and a mouth_counter.
Avatar
dhavalmistry
107 Posts
Posted Jun 04, 2011
Replied 1 hour later
It somewhat makes sense now....I will give it a try....will let you guys know if it works out...thanks :smile:
Avatar
yohoat9
274 Posts
Posted Jun 05, 2011
Replied 13 hours later

Idolon wrote:
Just use a logic_case and a mouth_counter.

:wut:

Avatar
Another Bad Pun
516 Posts
Posted Jun 05, 2011
Replied 43 minutes later
:potd:
Advertisement
Registered users don’t see ads! Register now!
Avatar
Idolon
417 Posts
Posted Jun 05, 2011
Replied 5 hours later

yohoat9 wrote:
Idolon wrote:

Just use a logic_case and a mouth_counter.

:wut:

Totally a legitimate entity, I swear!