What you learn today
- Read batteries in a slot
- ChargeRatio
- “full” indicator
Battery cells for tools and wall lights end up in the battery charger. The large charger (StructureBatteryCharger) has 5 slots, the small one (StructureBatteryChargerSmall) 2. Which battery is full, which still needs time? The chip tells you before you walk over.
What a battery in a slot reports
| LogicSlotType | Meaning |
|---|---|
Occupied | is a battery in the slot? |
Charge | stored energy in J |
ChargeRatio | charge level from 0 to 1 |
ChargeRatio is the value you work with: 0.5 means half full, 1 means full. For percent multiply by 100.
lbs ratio CHARGER 0 ChargeRatio Average # slot 0
mul percent ratio 100
With one charger on the network Average returns exactly its value – and NaN if the charger is missing. You already know the NaN guard for that.
An empty slot reports ChargeRatio 0, just like an empty battery. So always check Occupied first. Otherwise your chip reports “battery empty” although there is simply none inside.
How fast a tool empties its cell when building and deconstructing does not depend on the tool: every finished build or deconstruction step costs a flat 1,000 J. Loose cells also lose up to 50 J per tick in cold below 0 °C.
“All full” across all slots
A slot is fine if it is empty or its battery is full. All slots together are fine if every single one is fine. That is an and across the loop:
move allFull 1
move i 0
slot:
lbs present CHARGER i Occupied Average
lbs ratio CHARGER i ChargeRatio Average
sge ok ratio FULL # full?
seqz empty present # or empty?
or ok ok empty
and allFull allFull ok
add i i 1
blt i SLOTS slot
Use 0.99 as the limit instead of exactly 1. Whether the value reaches exactly 1 in the game depends on the calculation behind it. A threshold keeps you on the safe side.
An empty charger is not “full”
If no battery is inside at all, every slot is “fine” and the lamp would report “full”. Count the batteries as well and require at least one:
add count count present # inside the loop
sgtz present count # after the loop
and allFull allFull present
If the charger is missing entirely, count becomes NaN. sgtz then returns 0 and the lamp stays off. For the display you replace NaN with 0 using snan and select.
According to the Stationpedia the large charger draws 10 W even when it charges nothing. If you need to save power, set On to 0 as soon as everything is full.
Diagram
Exercise
Task
A battery charger (StructureBatteryCharger, 5 slots) sits on the network.
- The wall light “Voll” is on when at least one battery is inside and every battery in the charger has at least 99 %.
- The LED display “Akkus” shows how many batteries are in the charger.
- If the charger is missing: lamp off, display 0, no error.
Hints
Hint 1
A slot is fine if ChargeRatio ≥ FULL or Occupied = 0.
Hint 2
Combine all slots with and allFull allFull ok – set allFull to 1 first.
Hint 3
After the loop: replace NaN in count with 0 via snan/select, then sgtz and one more and.
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