Zum Hauptinhalt gehen

Suche

What would the logic for creating a combination lock be?

  • TheRockyTuna

    I feel like an IF gate would solve all of this, but sadly there is none...

  • Riandisa

    There's an example of an if/else gate in the gadgets section that someone made, which might help you. https://indreams.me/element/b6Z8J69Uj0w

    I think in If statements a lot myself and wish there was a default logic gadget for it.

  • Changeling_Storm

    I would use multiple counters and a selector (starting on port A). The position of the dial I would wire into the Current Count of all the counters.
    - Add a button input to proceed to selector port B, which would lock the first counter and enable the second one.
    - Repeat to proceed to selector port C, etc.
    - Then, use a calculator (set to =) to test if the current values are exactly right.
    - Place an AND gate. Wire it up so that it lights up only if a button is pressed, and all the = calculators return true.

  • Alados5

    I think it can be even simpler, but I’m writing this without the tools in hand so forgive me if something’s not right:
    - Stamp a selector, output port A will be on by default.
    - The idea is to go down a port letter every time a correct number is entered until everything’s correct, or go back to A if something’s wrong at any moment.
    - If output A is on AND the first digit is entered correctly, turn on port B directly. This will turn off port A automatically, I think.
    - If B is on AND the second digit is entered correctly, turn on port C.
    - Repeat until you’ve entered all digits of the code.
    - Last port’s output has to be connected to whatever you want to do when the code is entered correctly.
    - Now you only need to reset to A if you enter a wrong number, so just power A on with all the conditions (this might be tedious): port B on AND any input except the second correct digit, port C on AND any input except the third correct digit, and so on.
    - To reduce the number of gadgets, I would put a common “button pressed” signal for all digits and another one specific for each digit (“pressed 1”, “pressed 2”, etc). Now, if A is on AND “pressed” AND “pressed [first correct digit]”, power on B. If B is on AND “pressed” AND NOT “pressed [second correct digit]”, then go back to A. Maybe this is not optimal and it doesn’t help, so skip it if you’re not sure and you think it overcomplicates more than simplifies.
    - This solution is super simple and doesn’t require a lot of components, but you’ll have cable loops everywhere, from output A to input B, from B to C… Be prepared.

    Okay, so if it works, that’s it. But you might like to know this is a simplification of a “Finite State Machine”, a Sequential System very common in Electronics used for lots of stuff including this code application. Basically you have states, one corresponding to “nothing correctly guessed”, then “one number correct”, “two numbers correct”, etc., and you just go from one to the next if a correct digit is entered and go back to the first one if something’s wrong (like with the selector!). These states are usually represented with D latches and D flip-flops irl, which are totally doable here too, but in Dreams the simplest and fastest way to represent them is with counters (0-1). The selector simulates a way of representing these states that is, for me, the most clear one, with one and only one ON at a time, called “one-hot” (https://en.wikipedia.org/wiki/One-hot).

    So basically, you can do anything that can be represented with states like that and several counters or a selector. I really like this stuff so I could go on, and maybe this is already too much, but I think you might appreciate this knowledge for future logic creations!

    If the selector thing doesn’t work, try using counters simulating the expected behavior: the first one active (1) by default, if one is active and the next correct digit is entered power on the next one, and reset the previous one at the same time, and finally if an incorrect digit is entered, go back to the first state.

  • Alados5

    Oh, also, in Dreams, IF statements can be done simply with a condition (signal from logic, calculator, etc.) connected to a power port (of a gadget or a microchip containing the body of your if statement, what to do if the condition is met. So you can nest this structure to create your desired conditions and actions, if you prefer to do it that way!

Bitte melden Sie sich an, um einen Kommentar zu hinterlassen.