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:
| Mode | Name | Output 2 when … |
|---|---|---|
| 0 | All | all rules match |
| 1 | Any | at least one rule matches |
| 2 | None | no 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.:
| Instruction | Number | Structure of the rule |
|---|---|---|
FilterPrefabHashEquals | 1 | prefab hash · 256 + 1 |
FilterPrefabHashNotEquals | 2 | prefab hash · 256 + 2 |
FilterSortingClassCompare | 3 | class · 65,536 + comparison · 256 + 3 |
FilterSlotTypeCompare | 4 | slot type · 65,536 + comparison · 256 + 4 |
FilterQuantityCompare | 5 | quantity · 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.
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
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