stationeers.de Mod workshop · Dominik1199
DE Sign in
  1. Home
  2. IC10 academy
  3. Day 72

Day 72 of 365 · Beginner · Month 3: First systems

Counting storage

Quantity and MaxQuantity tell you how full a slot is. With lbs and Sum you count a whole store and work out the free slots.

Lesson 12 min Week 11

What you learn today

  • Quantity and MaxQuantity
  • Sum over many lockers
  • Compute free space

The ore store holds six lockers full of iron ore. How much is left? And when do you have to build another locker? Instead of opening every locker you let the chip count.

Quantity and MaxQuantity

Every slot reports two amounts:

LogicSlotTypeMeaning
Quantityhow many items sit in the slot
MaxQuantityhow many fit on this stack at most

A stack of iron ore with 37 of 50 items returns Quantity 37 and MaxQuantity 50. Things that do not stack, such as a tool, count as 1 of 1.

ls amount locker 0 Quantity      # items in slot 0
ls room locker 0 MaxQuantity     # fits on the stack at most
sub free room amount             # still free on this stack
Warning

An empty slot reports Quantity 0 and MaxQuantity 0 as well. So you can only work out the free space of a stack where something already sits. Empty slots are counted via Occupied instead.

Across many lockers: lbs with Sum

lbs reads one slot of all devices of a type. Amounts really add up, so Sum is right here and not Average:

lbs total LOCKER 0 Quantity Sum  # slot 0 of all lockers together

But a locker has more than one slot. The slot number may sit in a register, so a loop can run over all slots:

move total 0
move i 0
slot:
lbs value LOCKER i Quantity Sum
add total total value
add i i 1
blt i SLOTS slot

The small locker (StructureLockerSmall) has 4 slots, the normal locker (StructureStorageLocker) 30. A loop over 30 slots costs a good 120 instructions, almost a whole tick. In a store half a second does not matter.

Free slots

Occupied is 1 for a used slot. Summed over all lockers this gives the number of used slots. The number of lockers comes from Count:

lb lockers LOCKER PrefabHash Count
mul free lockers SLOTS
sub free free used

Count needs a LogicType the device can read, otherwise the chip reports IncorrectLogicType. Every device can read PrefabHash, so with it you are always right.

Tip

Only count with Count if all lockers of this type belong to the store. Count ignores names. We look at that more closely in week 14.

Diagram

A locker with numbered slots Locker (d0) Slot 0 Iron ore Occ 1 Qty 5 Slot 1 Copper ore Occ 1 Qty 12 Slot 2 empty Occ 0 Qty 0 Slot 3 empty Occ 0 Qty 0 ls r0 d0 0 Occupied r0 = 1 ls r1 d0 1 Quantity r1 = 12 Slots count from 0. Values in a slot are called LogicSlotTypes.
Every slot reports its quantity. lbs with Sum combines the same slot of all lockers, a loop runs over all slots.

Exercise

Task

Small lockers (StructureLockerSmall, 4 slots each) stand on the data network of the store. Count across all lockers:

  • the total number of items in all slots → LED display “Bestand”
  • the number of free slots → LED display “Frei”

If someone removes a locker, both numbers simply drop – without an error.

Hints

Hint 1

Reset total, used and i to 0 at the start of every pass.

Hint 2

Inside the loop use lbs … Sum twice: once Quantity, once Occupied.

Hint 3

Free slots = lockers × SLOTS − used slots. lb lockers LOCKER PrefabHash Count counts the lockers.

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

Esc
↑ ↓ selectEnter open/ opens search anywhere