What you learn today
- Translate a reagent hash into a prefab hash
- Find missing ingredients
- Combine with lr
The autolathe has accepted a job and stands still. It lacks material – but which, and which ingot would that be? lr tells you how much of which reagent is missing. rmap tells you what you have to put in for it.
The instruction
rmap ingot printer IRON
rmap r? d? reagent asks a device: “Which item fulfils this reagent for you?” On an autolathe, rmap returns the prefab hash of ItemIronIngot for HASH("Iron") – exactly what you have to fetch from storage. If the device knows no matching ingot, it returns 0.
Two restrictions apply, and both are in the game code like this:
- The device has to be a pin:
d0tod5ordb.rmapdoes not take a ReferenceId in a register. That is why the printer hangs ond0here. - The device has to be a fabricator that works through recipes – autolathe, electronics printer, tool manufactory and their relatives. A furnace is none;
rmapon a furnace stops the chip.
Combining with lr
lr … Required returns how much of the reagent the running job still lacks. If it is more than 0, rmap translates the reagent into the ingot:
lr missing printer Required IRON
blez missing check_copper
rmap ingot printer IRON
move amount missing
That way the chip checks a short list of reagents one after another. Whatever is checked last wins – put the most important material at the end.
Reporting missing ingredients
The result goes into a logic memory “Nachschub”. A second chip at the storage can read this prefab hash and have exactly this ingot dispensed – you will see how at the vending machine (day 243). A display shows the missing amount.
With a pin you need bdns: if the printer is missing on d0, lr and rmap would stop the chip. bdns printer failure jumps into a safe branch beforehand.
Why not just a table?
You could also store “Iron belongs to ItemIronIngot” yourself as defines. rmap has two advantages: it knows every reagent, alloys like Steel or Electrum too, and it stays right when a game update changes the ingots.
Exercise
Task
The autolathe hangs on d0. Check iron, copper and steel one after another with lr … Required. If something is missing, translate the reagent into the ingot hash with rmap. Write the hash to the logic memory “Nachschub” (0 if nothing is missing) and the missing amount to “Fehlmenge”; later checks overwrite earlier ones. If the printer is missing (bdns): “Nachschub” −1, light “Druckerfehler” on.
Hints
Hint 1
Right at the start bdns printer failure, the branch failure: at the bottom.
Hint 2
Per reagent: lr missing printer Required …, blez to the next label, rmap, move amount missing.
Hint 3
In the normal branch explicitly write the fault light to 0.
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