[quote name='Torgo']Is it possible to write a script for a probe that would sense the current battery level, then switch a fuel cell on based on that level?
I'd like to have the fuel cell kick on when the battery gets to 10%, then switch off when the battery gets to 90%.[/QUOTE]
[CODE]
list RESOURCES in res.
local capacity is 0.
local amount is 0.
for r in res {
if r:NAME = "ElectricCharge" {
lock capacity to r:CAPACITY.
lock amount to r:AMOUNT.
break.
}
}
local isON is false.
until false {
local p is 0.
if capacity > 0 {
set p to amount/capacity.
}
if p <= 0.1 and not isON {
list PARTS in pp.
for part in pp {
if part:NAME = "FuelCell" or part:NAME = "FuelCellArray" {
local module is part:GETMODULE("ModuleResourceConverter").
if module:HASEVENT("start fuel cell") {
module:DOEVENT("start fuel cell").
}
}
}
set isON to true.
} else if p >= 0.9 and isON {
list PARTS in pp.
for part in pp {
if part:NAME = "FuelCell" or part:NAME = "FuelCellArray" {
local module is part:GETMODULE("ModuleResourceConverter").
if module:HASEVENT("stop fuel cell") {
module:DOEVENT("stop fuel cell").
}
}
}
set isON to false.
}
wait 5.
}
[/CODE]
you can optimize it by taking parts' listing out of until loop