What you learn today
- Logic reader, writer, compare and math
- When a chip is better
- Combining both
Not every control needs a chip. The game has a whole family of small logic devices that you set up with the screwdriver. They read a value, compare, calculate and write, without a single line of code.
The four most important
| Device | Prefab | does | result in |
|---|---|---|---|
| Logic Reader | StructureLogicReader | reads a LogicType of a chosen device | Setting |
| Logic Writer | StructureLogicWriter | writes the value of its input into a target | at the target |
| Logic Compare | StructureLogicCompare | compares two inputs: Equals, Greater, Less, NotEquals | Setting (0/1) |
| Logic Math | StructureLogicMath | calculates with two inputs: Add, Subtract, Multiply, Divide, Mod, Atan2, Pow, Log | Setting |
Compare and math work with the Setting of their input devices. A chain looks something like this: a reader reads the room temperature, a logic memory holds the setpoint, a compare checks “less”, a writer switches the heater. Which device and which value a reader reads is set with the screwdriver. According to the game data each of these four devices draws 10 W.
When a chip is better
Logic devices are good for one single, simple rule that everyone in the room should see and understand. As soon as more comes along, the chip wins:
| Task | logic devices | chip |
|---|---|---|
| one comparison, one action | good | works too |
| hysteresis with memory | clumsy | four lines |
| sensor missing, safe state | hardly possible | snan, bdns |
| timers, sequences | no | yes |
| many devices by name | no | lbn, sbn |
A detail from the game code: Equals and NotEquals in the logic compare compare with a small tolerance, not exactly like seq.
Three traps from the game code
- Reader without a target: if the device a logic reader reads is removed, it reports
Error1 – but itsSettingkeeps the last value. A chip that only readsSettingnotices nothing and keeps calculating with an old value. So readErroras well. - Writer only writes on change: a logic writer only writes again when its input or its target changes. If someone has changed the target by hand in the meantime, it stays that way. With
ForceWrite1 you force it to write again on the next tick. - Batch reader needs an output: the logic batch reader only works when a data cable hangs on its output as well. Otherwise it reports
Error1.
Combining both
The chip can read any logic device like any other device. The Setting of a compare is then 0 or 1, that of a math device a calculation result:
lbn night COMPARE HASH("Nacht") Setting Average
lbn total MATH HASH("Summe") Setting Average
That way a chain that already exists feeds a chip. Or a chip puts a setpoint into a logic memory, and a simple chain at the other end of the base evaluates it.
Logic devices need power and can be removed like any device. Guard values from a chain just like sensor values: if the device is missing, lbn … Average returns NaN.
Start with a chip right away if you already know that “just one small thing” will be added later. Rebuilding is more work than building it right in the first place.
Diagram
Exercise
Task
Kolja has already built a logic chain. A logic compare “Nacht” reports 1 when it is dark, a logic math “Summe” adds up the power of two solar fields. Your chip reads both:
- Wall lights “Hoflicht” follow the compare. If the compare is missing: light on.
- LED “Leistung” shows the
Settingof the math device. If the device is missing: −999.
Hints
Hint 1
Both results sit in the Setting of the logic devices.
Hint 2
Light: snan, sgtz, then or with the failure.
Hint 3
Display: select total missing NOVALUE total.
Quiz
5 questions. You pass from 60 % – the server does the grading.
Complete the day
- Passed the simulator exercise
- Passed the quiz with at least 60 %
Without an account progress is saved in this browser only.
Report a mistake in this lesson
Please sign in to report. Sign in