What you learn today
- Compare lbs and lbns
- Specific lockers by name
- Batch mode for slots
The store holds twelve small lockers. Three are called “Eisen”, two “Kupfer”, the rest “Werkzeug”. With lbs you read a slot of all lockers of the type. For the question “how much iron do I have?” you only need the lockers with the right name. That is exactly what lbns does.
lbs and lbns compared
lbs r0 LOCKER 0 Quantity Sum # slot 0 of all lockers
lbns r1 LOCKER HASH("Eisen") 0 Quantity Sum # only lockers "Eisen"
| Instruction | filters by | operands |
|---|---|---|
lbs | type | r? hash slot SlotType mode |
lbns | type and name | r? hash nameHash slot SlotType mode |
lbns relates to lbs like lbn to lb. The name comes third, right after the prefab hash.
Batch mode for slots
The batch modes work the same here, with the same results for zero matches:
| Question | Mode |
|---|---|
| How many items in total? | Sum |
| How full is the emptiest battery in the chargers “Werkzeug”? | Minimum |
| Is anything ripe in the trays “Tomaten”? | Maximum |
| How far are the plants on average? | Average |
With Sum a missing locker returns 0, with Average NaN. For a store 0 is the more honest answer: where there is no locker, there is no iron either.
All slots of one name
As with lbs the slot number may sit in a register. A loop then counts all slots of the lockers with one name:
move total 0
move i 0
slot:
lbns value LOCKER HASH("Eisen") i Quantity Sum
add total total value
add i i 1
blt i SLOTS slot
A name only hits devices of the same type. A small locker “Eisen” and a large locker “Eisen” are two different prefabs. lbns with the hash of the small locker does not see the large one.
An LED display may have the same name as the lockers whose contents it shows. The type tells them apart. That way the name on the display matches the storage place.
Diagram
Exercise
Task
The store holds small lockers (StructureLockerSmall, 4 slots) named “Eisen” (two of them), “Kupfer” and “Werkzeug”.
- LED display “Eisen”: all items in all slots of the lockers “Eisen”
- LED display “Kupfer”: the same for “Kupfer”
- If a locker is missing, it simply does not count – without an error.
Hints
Hint 1
Reset the totals and i to 0 at the start of every pass.
Hint 2
Inside the loop lbns … i Quantity Sum twice, once with HASH("Eisen"), once with HASH("Kupfer").
Hint 3
After the loop write both displays with sbn.
Quiz
4 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