How to construct Boolean operators?

Simply, I got these functions:

Input v is a table containing the inputs of the logic gate.
Input m is just the toggle of the certain object, only needed for the SWITCH gate.

The player will be able to pack many of the basic gates listed in the dictionary above, but as well as other packed gates.

But with the speed I’m simulating the gates on (in the client) being like 8 gates per frame, I need to simulate packed gates at the same speed as basic gates.

Any ideas on how to make a method to run loads of Boolean operations ( AND, NOT, OR ) in a single line, like how the basic gates are run, instead of keeping to run functions?

1 Like

bumping post !!!

1 Like

I don’t have an exact answer for this but you could check out “logic minimization”. Here are a couple links that might give you some ideas:

1 Like

have you taken a look at the built in bit32 library? bit32 | Documentation - Roblox Creator Hub This library includes all the primitive logic functions needed for your logic gates

edit: all these logic functions take in tuple arguments as well

Check my profile, I’ve made a tutorial on Bit32 aswell as a module for the library, In my case instead of needing 32 bits for logic operations, I just need 1 bit.

couldn’t you use the library regardless, and just truncate the leading bits?

To adapt my method to bit32, I’d need to use 1’s and 0’s instead of booleans which I use currently, and for my case c = a and b is far better than c = bit32.extract(,c), 0)

So to clarify what you want. For example, if you wanted to make a half adder, you want to make a function for it similar to the ones in your baseFunctions table by only using the ternary operators?

Yeah, the goal is to combine the operators in the baseFunctions into a single line of temary operators.

I’m sorry, I don’t really see the issue here exactly. Wouldn’t you just do something like this?

H_ADDER = function(v:{}) return (v[1] or v[2]) and not (v[1] and v[2]), v[1] and v[2] end

edit: for each new packed gate added you’d just do the same thing

Packed gates are assembles from other packed gates or basic gates by the player

To me, it seems like you’re going to have to hard code each packed gate if you want it to run all the turnery operators on one line. Or you’re going to need to create your own compiler so that it sets it up that way during runtime.

Wait, can’t I just construct a function with loadstring()?