| Blockland Forums > Modification Help |
| | and & vs || and &&? |
| << < (2/5) > >> |
| Port:
--- Quote from: ThinkInvisible on March 11, 2012, 10:34:37 AM ---Yes, it does. Ex. containerRadiusSearches: --- Code: ---while(%storage = containerSearchNext) --- End code --- While there are objects that can be found by the search, while loop is true. --- End quote --- First of all, it's containerSearchNext(). Secondly, if you do something like the following, it doesn't do an if check such as %pl == %cl.player, it sets %pl to %cl.player and then checks the value of %pl: if ( isObject( %pl = %cl.player ) ) A variable definition returns the value. Try it: --- Code: ---echo( $a = "hello" ); echo( $a SPC "world" ); --- End code --- |
| Headcrab Zombie:
| and & (along with << >> ^ and if Torque supports it, ~) are bitwise operators http://www.cprogramming.com/tutorial/bitwise_operators.html That link is for C/C++ but the syntax is the same thing --- Quote from: ThinkInvisible on March 11, 2012, 10:34:37 AM ---Yes, it does. while(%storage = containerSearchNext()) --- End quote --- == Always compares, it never sets = Always sets, it never compares Whats happening here (after I added (), bolded) is you are calling the function containerSearchNext, which will either return the next object, or a 0 if no object is found. %storage is then set to the value returned by containerSearchNext, then the while loop checks the value of %storage - a non-zero value results in it continuing the loop, zero (no object found) it will end the loop. |
| Greek2me:
This is the topic for you: http://forum.blockland.us/index.php?topic=178383.0 |
| phflack:
thanks |
| DontCare4Free:
However, there is a more important difference, when just testing for booleans. Logical or (||) and logical and (&&) short-circuit. This means that if it can figure out the value from the first part (first part is true for or, first part is false for and), the second argument will not even execute. Since the binary operators (| and &) have to support more than one bit, it's impossible to short-circuit reliably, which can be useful, even when only dealing with a single bit. |
| Navigation |
| Message Index |
| Next page |
| Previous page |