Please or Register to create posts and topics.

If's and Conditional Statements

Page 1 of 2Next

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.

Dont know much about them hopefully, these will help you

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

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

I've always used overly intricate combinations of logic_relays by disabling and triggering them to produce logic functions.

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.

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.

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.

Portal 1.5 http://www.moddb.com/mods/portal-15
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.

I am lost :(

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).

Portal 1.5 http://www.moddb.com/mods/portal-15
dhavalmistry wrote:
I am lost :(

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.

Page 1 of 2Next