What you learn today
- Read stock
- Trigger output
- Refill storage
The name is a little misleading: the vending machine (StructureVendingMachine) is above all a storage machine with 100 slots that takes items in via the chute and hands them out again on request – by button on the device or by chip. According to the Stationpedia it is also the distribution point for trading: without it (or its refrigerated variant) you cannot trade with traders.
Reading the stock
Slot 0 is the input, slot 1 the output, slots 2 to 101 are the store.
| LogicType | Meaning |
|---|---|
Quantity | how many storage slots are occupied |
Ratio | the same as a share: occupied slots divided by 100 |
RequestHash | write: dispense an item with this prefab hash |
DispenseSlot | write: dispense the content of this slot (2–101) |
TargetSlotIndex, TargetPrefabHash | what is selected right now |
Careful: Quantity counts slots, not pieces. A slot with 500 ingots counts as much as one with a single ingot. How many iron ingots exactly are inside you find with a loop over the slots:
lbns kind VENDING HASH("Lager") i OccupantHash Average
seq kind kind IRON
lbns tmp VENDING HASH("Lager") i Quantity Average
select tmp kind tmp 0
add total total tmp
Triggering output
sbn VENDING HASH("Lager") RequestHash IRON
Every write of RequestHash is an order. Whoever passes the button through every tick orders every tick. That is why the chip only orders on the rising edge – at the moment of pressing, not while it is held. You know the pattern from the button as a switch.
Refilling the store
When the machine empties, the chip opens a chute valve in front of its input, and supplies run in from a silo. With hysteresis: below 30 % open, from 90 % closed. In between it stays as it is.
If the machine is missing, Ratio is NaN. Both comparisons give 0, the valve stays closed. Supplies into a store the chip cannot see end up as a pile on the floor.
Exercise
Task
The vending machine is named “Lager”. Show Quantity on “Belegt” (−1 without machine). The chute valve “Nachschub” opens below 30 % (Ratio) and closes from 90 %. A press on the button “Eisen” orders exactly once: RequestHash = hash of ItemIronIngot, only at the moment of pressing.
Hints
Hint 1
Display: snan and select … -1.
Hint 2
Refill: slt/and with HIGH, slt/or with LOW.
Hint 3
Edge: seqz tmp old, move old press, and tmp tmp press – order only then.
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