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

Day 241 of 365 · Pro · Month 9: Logistics and greenhouse

The logic sorter

The logic sorter decides by itself – by rules that a chip writes into its memory. Every rule is a number made of instruction, comparison and value.

Lesson 25 min Week 35

What you learn today

  • Sorting instructions in memory
  • SorterInstruction values
  • Combine rules

The sorter in logic mode needs a decision from the chip for every item. The logic sorter (StructureLogicSorter) decides by itself – by rules in its own memory. The chip writes the rules in once, and after that the machine sorts on its own.

How it decides

The logic sorter has a memory with 32 slots. Every slot is a rule. If the item in the input matches the rules, it goes to output 2, otherwise to output 1. How the rules work together is set by Mode:

ModeNameOutput 2 when …
0Allall rules match
1Anyat least one rule matches
2Noneno rule matches

A slot with 0 is empty and gets skipped.

SorterInstruction values

Every rule is a number put together from parts. The lowest byte is the instruction from the namespace SorterInstruction.:

InstructionNumberStructure of the rule
FilterPrefabHashEquals1prefab hash · 256 + 1
FilterPrefabHashNotEquals2prefab hash · 256 + 2
FilterSortingClassCompare3class · 65,536 + comparison · 256 + 3
FilterSlotTypeCompare4slot type · 65,536 + comparison · 256 + 4
FilterQuantityCompare5quantity · 65,536 + comparison · 256 + 5

The comparison is 0 for equal (Equals), 1 for greater (Greater), 2 for less (Less), 3 for not equal (NotEquals). “Greater” means: the item's value is greater than the value in the rule. “Quantity greater 10” therefore hits stacks from 11 pieces.

Times 256 shifts a number one byte to the left, times 65,536 two. You learn bit instructions later in the year – for these rules multiplying and adding is enough. Negative prefab hashes work this way too, because the sorter only reads out the right bytes.

mul b1 ORES TWO_BYTES
mul tmp EQUALS BYTE
add b1 b1 tmp
add b1 b1 CLASS_CMP

ORES is 9, CLASS_CMP is 3. So the rule “class equals ores” is the number 589,827.

Writing into the memory

Another device's memory is written with put device address value. The device here is the ReferenceId:

put id 0 b1
put id 1 b2

With Mode 0 (All) and the two rules “class ores” and “not dirty ore” all real ores go to output 2.

Warning

Old rules stay in the memory until they are overwritten. If something stood in slot 2 before, it still applies. With clrd id you clear the whole memory – once before rewriting, not every tick.

Diagram

The stack with its pointer slot 0 10 slot 1 20 slot 2 30 slot 3 slot 4 sp = 3 next free slot push 40 pop r0 r0 = 30 last in, first out
32 memory slots, each one a rule. An empty slot (0) is skipped.

Exercise

Task

Program the logic sorter “Erzfilter”: rule 1 (address 0) checks “class equals Ores”, rule 2 (address 1) “prefab hash not equal ItemDirtyOre”. Calculate the rules in b1 and b2, write them with put via the ReferenceId and set Mode 0 (All). If the sorter is missing (bdns), “Filterfehler” lights up, otherwise it is off.

Hints

Hint 1

Rule 1: class times 65536, comparison times 256, plus instruction 3.

Hint 2

Rule 2: hash times 256 plus instruction 2 – also with a negative hash.

Hint 3

put id 0 b1, put id 1 b2, then write Mode.

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

Esc
↑ ↓ selectEnter open/ opens search anywhere