Stationeers

Stationeers

View Stats:
IC10 Coding help and critique please.
Let's start with the critique first. I know I use more registers than necessary for variables and that these basic scripts don't really need for me to avoid using the pins but I prefer to have the code easily readable and removing reliance on pins is the goal. Same reason I mostly use hash names and not just the number. What else would you do different? Where can I improve? Appreciate any tips and tricks.

Below is my basic habitat ic code. Turns on a valve to a radiator if it gets too hot. Turns my fridge off once it is below 0c. Mick recommended it to save power. Temp only goes up when I open the door and/or put hot food in it. Finally it also switches my grow light on when the sun raises.

It works as intended and I'm using the single port data power combo version of the housing.
0. #Basic Hab Sys 1. #Temperature, Fridge, & Grow Light 2. 3. #Constants 4. define roomTemp 303 5.define fridgeTemp 272 6. 7. #Devices 8. alias lightsensor r0 9. alias roomsensor r1 10. alias growlight r2 11. alias thermastat r3 12. alias foodlocker r4 13. 14. #Variables 15. alias sensorVar r5 16. 17. 18. #Device Initialization 19.lbn lightsensor HASH("StructureDaylightSensor") HASH("DaylightSensor") ReferenceId Average 20. lbn roomsensor HASH("StructureGasSensor") HASH("InternalSensor") ReferenceId Average 21. lbn growlight HASH("StructureGrowLight") HASH("GrowLight") ReferenceId Average 22. lbn thermastat HASH("StructureDigitalValve") HASH("TemperatureValve") ReferenceId Average 23. lbn foodlocker HASH("StructureFridgeBig") HASH("Fridge") ReferenceId Average 24. 25. start: 26. yield 27. #GrowLight 28. l sensorVar lightsensor SolarIrradiance 29. sgtz sensorVar sensorVar 30. s growlight On sensorVar 31. #Thermastat 32. l sensorVar roomsensor Temperature 33. sgt sensorVar sensorVar roomTemp 34. s thermastat On sensorVar 35. #Fridge 36. l sensorVar foodlocker Temperature 37. sgt sensorVar sensorVar fridgeTemp 38. s foodlocker On sensorVar 39. j start

Now below this is some simple solar tracking for Mars. I'm using the single port data power combo on the solar panels here. Therefore I have to use the double port ic house so that I don't create a loop back to the batteries. A solar sensor leads up and enters the ic housing dataport before continuing up further to bring that data to the solars. Ic is powered by the internal wiring via the airlocks area power controller. So everything is hooked up right.

But I could not for the life of me get this code to work. I get an error flagging line 13. Device not found. I numbered them to make it easy to find. As you can see I am using a different daylight sensor. I have no problem checking the SolarIrradiance in the previous code from a daylight sensor but I can't seem to load the Horizontal data without this error of device not found. I also tried using the hash number instead of pulling it with the hash command. I lost track of how many times I double checked everything is labeled and wired correctly.

I thought having the same name even though on separate networks was the issue so I added the 2 to DayLightSensor2 during troubleshooting. I remove the spaces with the labeler as they gave me issues in a different program. I next thought it was the sb command which is why I gave the solar panels a label and register as well. That's why those lines are commented out. I also checked with the screw driver to see if the daylight sensor was on the network and it is.

0. #Solar Tracking 1. 2. #Devices 3. alias daysensor r0 4. alias panels r1 5. #Variables 6. alias verticalAngle r2 7. alias horizontalAngle r3 8. 9.#Initialize Devices 10. lbn daysensor HASH("StructureDaylightSensor") HASH("DayLightSensor2") ReferenceId Average 11. lbn panels HASH("StructureSolarPanel") HASH("SolarPanel") ReferenceId Average 12. start: 13. l verticalAngle daysensor Vertical 14. sub verticalAngle 90 verticalAngle 15. l horizontalAngle daysensor Horizontal 16. 17. s panels Vertical verticalAngle 18. s panels Horizontal horizontalAngle 19. #sb -2045627372 Vertical verticalAngle 20. #sb -2045627372 Horizontal horizontalAngle 21. j start


This is my working code. The only difference is I commented out the daylight sensor initialization and I switched from r0 to d0 and it works flawlessly. Where am I going wrong? What am I not seeing? Why can't I pull Horizontal from the daylight sensor but I can pull SolarIrradiance using the same method?
#Solar Tracking #Devices alias daysensor d0 alias panels r1 #Variables alias verticalAngle r2 alias horizontalAngle r3 #Initialize Devices #lbn daysensor HASH("StructureDaylightSensor") HASH("DayLightSensor2") ReferenceId Average lbn panels HASH("StructureSolarPanel") HASH("SolarPanel") ReferenceId Average start: l verticalAngle daysensor Vertical sub verticalAngle 90 verticalAngle l horizontalAngle daysensor Horizontal s panels Vertical verticalAngle s panels Horizontal horizontalAngle #sb -2045627372 Vertical verticalAngle #sb -2045627372 Horizontal horizontalAngle j start
Originally posted by no_signal40:
I ran your solar panel code and it works, so you probably gave the daylight sensor the wrong name.
< >
Showing 1-10 of 10 comments
Another noob here: from my limited experience there is a define command to assign the devices. That way you can assign the hash to your program keyword. Then you can define the individual sensors to keep them separate. You use the labeler to rename the specific sensors. Something like:

Define sensor HASH(“StructureDaylightSensor”)
Define sensor1 HASH(“daysensor1”)
Define sensor2 HASH(“daysensor2”)

lbn sensor sensor1 Vertical Sum
lbn sensor sensor1 Horizontal Sum

That kind of thing
l verticalAngle daysensor Vertical

You can't use a register as a device pointer. Changing to d0 'fixed' that.
Am I not using registers as device pointers in the entire first code?

The solar panels in the same code also uses a register to store the ReferenceId.

This is how you can exceed the 6 pin device limit. At least that was my understanding.
Originally posted by Ghevd:
Am I not using registers as device pointers in the entire first code?

I think this might be the source of your confusion, or you're misrepresenting your answer.

A "register" stores a value for you to access within your code.
A "device" is the thing you want to Read or Write a register value to.

If you use the "d#", then you are using a screw (0-5) to identify the particular device you want to access, but this option limits you to 6 devices, or the number of screws available on that particular device (Atmospherics has only 2, for example).

To access devices beyond the 6 screw limit, you have to use the Batch or Named Batch command to locate the device. This simply allows you to use code to identify the device instead of using a screw.

So for example, to assign an alias of "daysensor" to your daylight sensor, you can use a couple of options...

1) alias daysensor d0 #assigns Screw #1 to "daysensor"

2) define daysensor HASH(“StructureDaylightSensor”) #assigns the Hash code for the daylight sensor.


Since we're interested in using batch calls, we will need to know how many devices of that type are on the network to determine which batch style to use best. If there is more than one, you need to know that a batch will access all of those devices at once, unless you do a named batch option to identify a specific uniquely named device.

lb r0 daysensor Vertical Average
This would load the Vertical angle value from "all" daylight sensor it could find on that network and provide you an average of all those values. So if you had two installed at different angles, one might read 0 and the other 180 and your result would be 90.

lbn r0 daysensor HASH("DayLightSensor2") Vertical Average
This would load the Vertical angle from a daylight sensor that was named "DayLightSensor2". Since this is a batch call, you still need to use one of the multi-value handling options for the numbers (Average, Sum, Minimum or Maximum) because you could still have multiple devices with duplicate names and the IC needs to know how to handle multiple numbers.

Hope this was helpful.
Thanks JeanDeaux but your missing the one crucial part of my code. Even if I had 20 daylight sensors on the same network each one has a unique ReferenceId.

That is what I am storing in the registers, the unique id. That is why you see HASH called twice in the same line. One for the device type and the second for that devices unique name.

I guess I should have numbered the lines in the first bit of code as well.

The code flag here isn't displaying the code properly. Let me fix that....

Numbered the lines in the first code. Hopefully it is a bit more legible.

So when I write this:

lbn lightsensor HASH("StructureDaylightSensor") HASH("DaylightSensor2") ReferenceId Average

That is only one line of code in game. The reason Average works is because I only have one daylight sensor renamed to DaylightSensor2.

Since only one daylight sensor has that unique name the average is itself which is the unique reference id.

In other words I'm taking all the reference ids and adding them up then dividing by the number of reference ids added, which is 1. Anything divided by 1 is itself. Regardless of which batch mode I use I would get the same number. I only use average because that was the way I was taught this.

If I rip a device off the wall and put it back on, it will have a new unique reference id. You can see these ids with the configuration cartridge too. They start with a $ character.

If ya look at the template for lbn you can see the first hash in line is the devicehash the second hash after that is the namehash.

lbn r? deviceHash nameHash logicType batchMode
The author of this thread has indicated that this post answers the original topic.
I ran your solar panel code and it works, so you probably gave the daylight sensor the wrong name.
Originally posted by no_signal40:
I ran your solar panel code and it works, so you probably gave the daylight sensor the wrong name.
Which one? There's two solar panels codes there. I know the bottom one works.
the middle code
Originally posted by no_signal40:
the middle code

You're right. Thank you! My best guess is I had a space at the end when I labeled it. I used copy paste to make sure typically.

If it was a bug then quitting and restarting was the solution if not then it is human error on me. I feel like an idiot now. I've been at this for hours and settled for using the pins.

Thanks again!
Originally posted by hektor:
l verticalAngle daysensor Vertical

You can't use a register as a device pointer. Changing to d0 'fixed' that.
No; I'm pretty sure that as of the "Biggest update ever" update, that's a thing that you can do (actually, to be more precise, ever since the d load & store instruction variants (ld & sd) were deprecated in favour of including the nescessary functionality into the regular instruction variants).

One could even use raw (immediate) reference IDs in the place of the device argument in the regular load & store instruction variants. Like the following is valid (assuming that you have a device with that reference ID):
l r0 $F00F Setting

The only thing that was promised to work, but it still doesn't is using an alias (yes, an alias specifically) as a way to bind a raw / immediate reference ID as a named device alias in the place of any device argument, as it seems like the code for that is just missing outright / was backdated to before the introduction of that for some reason.
< >
Showing 1-10 of 10 comments
Per page: 1530 50

Date Posted: Dec 20, 2025 @ 6:12pm
Posts: 10