| Blockland Forums > Modification Help |
| | and & vs || and &&? |
| << < (3/5) > >> |
| phflack:
does it matter if things short circuit in BL though? i don't see the point as much when it doesn't complain too much (ie, instead of stopping the program) |
| DontCare4Free:
--- Quote from: phflack on March 11, 2012, 11:36:18 PM ---does it matter if things short circuit in BL though? i don't see the point as much when it doesn't complain too much (ie, instead of stopping the program) --- End quote --- --- Code: ---if (somethingThatMayFail() & somethingElseThatMayFailThatIsIndependent()) { // Bleh } --- End code --- vs --- Code: ---if (somethingThatMayFail() && somethingThatDependsOnTheFirstFunction()) { // Bleh } --- End code --- |
| Port:
--- Quote from: DontCare4Free on March 12, 2012, 02:30:57 AM --- --- End quote --- An example of the importance this has could be something like the following: --- Code: ---if ( isObject( %pl = %cl.player ) && ( !isObject( %mn = %pl.getMountedImage( 0 ) ) || %mn.getName() !$= "myWeaponImage" ) ) { %pl.mountImage( myWeaponImage, 0 ); } --- End code --- If && and || weren't short-circuit, this would cause console errors if there was no player or they were not holding something in slot 0. |
| phflack:
--- Quote from: Port on March 12, 2012, 04:15:07 AM ---An example of the importance this has could be something like the following: --- Code: ---if ( isObject( %pl = %cl.player ) && ( !isObject( %mn = %pl.getMountedImage( 0 ) ) || %mn.getName() !$= "myWeaponImage" ) ) { %pl.mountImage( myWeaponImage, 0 ); } --- End code --- If && and || weren't short-circuit, this would cause console errors if there was no player or they were not holding something in slot 0. --- End quote --- true, it does stop console errors, but it doesn't change the functionality, does it? |
| Ipquarx:
--- 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. --- Code: ---%a = 0; while(%a = 1) %a += 1; --- End code --- infinite loop - and actually runs, because %a can be set to 1 --- End quote --- This is ridiculous. Absolutely ridiculous. NO. ITS NOT. YOU'RE WRONG. == is to test if something equals something else = is to SET SOMETHING to SOMETHING ELSE. Oh my gosh. |
| Navigation |
| Message Index |
| Next page |
| Previous page |