Logic in Bitbybit
View Full Source & Details on GitHub
The Logic class in Bitbybit provides fundamental tools for working with boolean logic (true/false values), making comparisons, and controlling program flow based on conditions.
What is Boolean Logic?
Boolean logic revolves around two states: true or false. These are essential for making decisions in any programming or design task. For example, "Is this object visible?" (true/false), or "Is this number greater than 10?" (true/false).
Core Capabilities of the Logic Class
The Logic class helps you create, manipulate, and use boolean values effectively. Here's a high-level look at its features. For the exact input parameters, comparison operator symbols, and detailed behaviors, please consult the full Logic API documentation or the GitHub source linked above.
1. Creating Boolean Values and Lists
Need to define a boolean or a sequence of them?
- Single Boolean (
boolean()): Directly specify atrueorfalsevalue. This is useful in visual programming to explicitly set a boolean input. - Random Boolean Lists:
randomBooleans(): Create a list of randomtrueorfalsevalues of a specified length. You can control the probability oftrueoccurring with a threshold.
- Booleans from Numbers (Thresholding):
thresholdBooleanList(): Convert a list of numbers into a list of booleans. Numbers below a specifiedthresholdbecometrue, and those at or above becomefalse(can be inverted).thresholdGapsBooleanList(): Similar to the above, but you define multiple "gap" ranges (pairs of min/max numbers). If a number falls within any of these gaps, it becomestrue.twoThresholdRandomGradient(): A more advanced method to convert numbers to booleans. It uses two thresholds to define ranges for guaranteedtrueorfalse, and a gradient randomization for numbers in between.
2. Manipulating Boolean Values
Basic operations on booleans:
- Not Operator (
not(),notList()): Inverts a boolean value (truebecomesfalse,falsebecomestrue). This can be applied to a single boolean or to every boolean in a list.
3. Comparisons and Conditional Logic
Making decisions based on data:
- Compare Values (
compare()):- Compare two values (numbers, text, etc.) using standard comparison operators like:
==(equal to, loose comparison)===(strictly equal to, type and value)!=(not equal to, loose)!==(strictly not equal to)<(less than),>(greater than)<=(less than or equal to),>=(greater than or equal to)
- The result of the comparison is always a boolean (
trueorfalse).
- Compare two values (numbers, text, etc.) using standard comparison operators like:
- Value Gating (Conditional Output):
valueGate(): Acts like a switch. If a provided boolean istrue, it passes through a specifiedvalue. If the boolean isfalse, it outputsundefined(nothing). This is useful for conditionally providing data to other operations.firstDefinedValueGate(): Given two input values, it returns the first one that is notundefined. If both areundefined, it returnsundefined.