Stationeers

Stationeers

View Stats:
Rigben Jan 11, 2023 @ 6:22am
Multi-tasking code possible?
Newb question probably but are you able to have a single script multi-task?

I am a coding newb so i'm learning as I go, I have been pretty successful so far and have made code for things like temperature control / grow lights / solar tracking / sensor lights.

I run into issues every-time I try to make one multi-task for example combining temperature control and and air cleaner code together (my code works for both on dedicated chips). Same result when I tried to setup 2 rooms with sensor lights with 2 different sensors / sets of lights. They never show errors but seem to only activate the first things I tell it to do.
< >
Showing 1-15 of 19 comments
JeanDeaux Jan 11, 2023 @ 6:50am 
I doubt we'll see multi-tasking, but what might solve your issue is a delay between commands. It's not uncommon to add a "YIELD" or "SLEEP (seconds)" to allow time for the game to process a series of commands without missing a beat.
Pfirsich1966 Jan 11, 2023 @ 6:53am 
All comparison commands beginning with 's' can be used for this.
e.g. seq or sge
They write a 0 or 1 into a variable and can be used to switch off or on.

l Temp TempSensor Temperature
sge ok Temp 299
s WallCooler On ok

Not the best example, but I think it shows what you want.

edit: And also look at the boolean comparisons.
In connection with 'select'
Last edited by Pfirsich1966; Jan 11, 2023 @ 6:59am
Rigben Jan 11, 2023 @ 6:57am 
Ok, I will try to work those in. I do use sleep for my solar tracking script that has a pre-adjust night-mode.

My question now is can this language do 2 things in the same chunk (main) for example a blt & bgt for 2 different things or will it always divert down the first set of blt / bgt before ever reading the 2nd set?
JeanDeaux Jan 11, 2023 @ 8:16am 
Sounds like your wanting more of a function type call, as in do a task then come back to the next line. There's a couple of ways to accomplish, I like using what Pfirsich1966 mentions, setting a register with a boolean value to perform any number of tasks vs jumping around in lines of code.

Take a look at "slt" and "sgt" instead of branching. Let's say if the temperature was less than 300 kelvin, I want to turn on a heater and activate a vent volume pump...

alias Sensor d0
alias Heater d1
alias VolPump d2
alias Var r0
alias Temp r1
Start:
l Temp Sensor Temperature #get the temperature
slt Var Temp 300 #if temp < 300 then Var = 1 else Var = 0
s Heater On Var #turn heater on/off
s VolPump On Var #turn volumne pump on /off
yield #wait a tic
j Start


Much easier than jumping around with conditional line branches.

Alternately, you can setup a function type call using "ra" as a return line #.

alias Sensor d0
alias Heater d1
alias VolPump d2
alias Var r0
alias Temp r1
Start:
l Temp Sensor Temperature #get the temperature
bltal Temp 300 HeatOn
bgtal Temp 299 HeatOff
j Start

HeatOn: #function call to turn on heater/vol pump
s Heater On 1
s VolPump On 1
j ra

HeatOff: #function call to turn off heater/vol pump
s Heater On 0
s Volpump On 0
j ra
LittleShade Jan 11, 2023 @ 8:25am 
#Tank Max pressure bypass v1.0
define MAX_PRESSURE 45636 #42636 #20265kPa, 45,636kPa
define PUMP_SET 10
alias rIterator r10
alias rTemp r11
alias rCurrPressure r6
alias rGasPumpFlag r7

Start:
yield
move rIterator 0
Loop:
sleep 1
jal _UpdateReference
jal _FunctionForDevice
add rIterator rIterator 1
bgt rIterator 2 Loop_End
j Loop
Loop_End:
j Start

_UpdateReference:
mul rTemp rIterator 3
add rTemp rTemp 1
jr rTemp
alias dGasTank d0
alias dGasPump d1 #Index 0
j Select_end
alias dGasTank d2
alias dGasPump d3 #Index 1
j Select_end
alias dGasTank d4
alias dGasPump d5 #Index 2
j Select_end
Select_end:
j ra

_FunctionForDevice:
bdns dGasPump Function_End
bdns dGasTank Function_End
l rCurrPressure dGasTank Pressure
sge rGasPumpFlag rCurrPressure MAX_PRESSURE
#s dGasPump Lock 0
s dGasPump Setting PUMP_SET
s dGasPump On rGasPumpFlag
#s dGasPump Lock 1
Function_End:
j ra
Rigben Jan 11, 2023 @ 9:13am 
Thanks everybody, helped me out alot.
ShizNator Jan 11, 2023 @ 9:19am 
If only they would put back a little TLC in the Computer and the Logic Motherboard :steamsad:
Last edited by ShizNator; Jan 11, 2023 @ 9:20am
Rigben Jan 11, 2023 @ 12:15pm 
This info allowed me to do everything I want to do. I combined my Temperature Control and Air Cleaner setup taking advantage of bgtal / bltal with j ra.

alias Sensor d0
alias AirCleaner d1
alias CurrentTemp r1
alias MaxTemp r2
alias MidTemp r3
alias MinTemp r4
alias CurrentPollutant r5
alias CurrentVolatiles r6
alias DesiredPollutant r7
alias DesiredVolatiles r8
add MaxTemp 273.15 28
add MidTemp 273.15 25
add MinTemp 273.15 22
abs DesiredPollutant 0
abs DesiredVolatiles 0

define WallCoolers -739292323
define WallHeaters 24258244

lifesupport:
l CurrentTemp Sensor Temperature
l CurrentVolatiles Sensor RatioVolatiles
l CurrentPollutant Sensor RatioPollutant
bgtal CurrentVolatiles DesiredVolatiles volaclean
bgtal CurrentPollutant DesiredPollutant pollclean
bltal CurrentVolatiles DesiredVolatiles idleclean
bltal CurrentPollutant DesiredPollutant idleclean
bgt CurrentTemp MaxTemp overtemp
blt CurrentTemp MinTemp undertemp
bgt CurrentTemp MidTemp idleheater
blt CurrentTemp MidTemp idlecooler
j lifesupport
overtemp:
sb WallCoolers On 1
j lifesupport
undertemp:
sb WallHeaters On 1
j lifesupport
idlecooler:
sb WallCoolers On 0
j lifesupport
idleheater:
sb WallHeaters On 0
j lifesupport
volaclean:
s AirCleaner On 1
j ra
pollclean:
s AirCleaner On 1
j ra
idleclean:
s AirCleaner On 0
j ra

For my automatic lights I simply used 2 sgt lines to check occupants against 0 and used those variables to trigger my lights (all without a jump aside from looping), this allowed me to have multiple rooms acting off the same chip. Only Limit is the amount of devices per housing,

alias MainHallSensor d0
alias MainHallLight1 d1
alias MainHallLight2 d2
alias MainHallLight3 d3
alias KitchenSensor d4
alias KitchenLight1 d5
alias OccupantsMainHall r1
alias OccupantsKitchen r2
alias MainHallLights r3
alias KitchenLights r4

main:
l OccupantsMainHall MainHallSensor Quantity
l OccupantsKitchen KitchenSensor Quantity
sgt MainHallLights OccupantsMainHall 0
sgt KitchenLights OccupantsKitchen 0
s MainHallLight1 On MainHallLights
s MainHallLight2 On MainHallLights
s MainHallLight3 On MainHallLights
s KitchenLight1 On KitchenLights
j main
JeanDeaux Jan 11, 2023 @ 1:06pm 
Congrats!
Shawn Jan 11, 2023 @ 6:42pm 
One of the things I love about this community is watching people who dip their toe into coding take to it like a fish to water. I really get a kick out of it.

Congrats OP. Made me smile for real.
LittleShade Jan 11, 2023 @ 7:34pm 
I think it would be good to consider the following.
1. using batch command to control Same devices
2. db value setting to control Main-sub IC housing
3. Communication between IC housings through encoding-decoding
Last edited by LittleShade; Jan 11, 2023 @ 7:36pm
Rigben Jan 12, 2023 @ 5:15am 
Originally posted by pippin2006:
I think it would be good to consider the following.
1. using batch command to control Same devices
2. db value setting to control Main-sub IC housing
3. Communication between IC housings through encoding-decoding

1 - I believe what you are referring to here is using the hash to control same items and I did use that "sb" i think in my life support code. The reason I did not use a batch command for my lights is because I wanted the rooms to be separate from each other while using same housing.

2 - I did some looking and is this referring to the debugging type thing that you can display the current line or register value to the housing? The examples on the wiki are "s db Settings r0" and "s db Settings 137".

3 - This one I failed to find documentation on can you give an example of this process? By the sounds of it you could essentially make a master script on 1 housing that can activate a connected housing (possibly through a device dial).
Remnar Jan 12, 2023 @ 5:30am 
It's cool you guys were able to brain storm a solution to a problem. As I read through the code, It donned on me that it seems inefficient, resource wise. Like, if the script has to repeat itself every tick, why not skip all the code under the comparison commands it relates to, like in basic? If you have a "if/then" block, the code under it would be skipped entirely if the result was false. Instead it has to keep sending signals regardless of outcome. I dunno, maybe I am thinking about it wrong? I watched a youtube video on IC10 to get a basic understand of it. My coding experience has been with old languages and python. I couldn't really understand ASM with all the push and pulls lol.
JeanDeaux Jan 12, 2023 @ 5:45am 
I get that skipping a few lines of code can save come cycle time, but MIPS lacks IF/THEN commands. You can code in some "branch" commands to skip a few lines in an attempt to save that cycle time, but it would come at a cost of using additional command lines to do so. With a small/short code you can likely do that but when you're attempting something a bit more complex and you need all 125 lines available to you then adding command lines simply to save cycle time becomes expensive real estate in your code. Simply re-sending a value takes fewer code lines than it does to force a skip.

It can also be beneficial to re-send commands. For example, if you add a new solar panel to an existing circuit and a Vertical or Horizontal value isn't changing, then the new solar panel won't receive the initial codes it needs for setup orientation (like on the Moon). If you're in multi-player and another player turns on/off something they shouldn't have, then resending the code to keep the item at the desired setting could save you from a catastrophic failure. So yes, the redundancy seems wasteful but there are benefits to doing so.

Push's and Pop's are more complex than I'm willing to cover just now. Plenty of Google searches can cover this topic, it's useful but can be tricky to use.
Remnar Jan 12, 2023 @ 5:50am 
It makes sense now to have it the way it is as you explained; thanks.
< >
Showing 1-15 of 19 comments
Per page: 1530 50

Date Posted: Jan 11, 2023 @ 6:22am
Posts: 19