BloxGaming Forums
Our Servers => BloxGaming SB3 => Expression 2 (E2) Code => Topic started by: kevinminion on October 08, 2015, 01:08:13 am
-
I'm trying to make a Life Support Control chip for my Gas Systems 3 components.
When I first spawn my ship, obviously everything is 0 so I want to turn on the collectors to start collecting Tritium, Methane, and Deuterium.
Once these have maxed out, I would like my Inverters to turn on so that I will start generating Oxygen, Water, and Nitrogen.
When my Tritium level gets to 10%, I would like the Tritium Inverter to turn off until Tritium is at 100% again (same for other 2 gas types)
So I should see my Tritium level increase until it gets to 100%, then go down to 10%, then back up to 100%, then down to 10% until Oxygen is at 100%
However, with the code below, it goes from 0% to 100%, then down to 10%, and hovers around 10%. The inverters switch on and off every second or so.
The Tritium Collector should stay on until Oxygen = 100% and Tritium = 100%
I'm sure I may just be tired, but maybe someone will solve this by tomorrow night :)
This is just a piece of the code. LastTritium is the Tritium value of the previous clock cycle. PctTritium is the current Tritium value divided by the max.
(LastTritium >= GS3StorageCache["Tritium",number]) should in essence be saying
if Tritium is discharging
But I think that line is most likely where I am screwing up.
Trit_Inverter_On = 0
Meth_Inverter_On = 0
Deut_Inverter_On = 0
if ((PctOxygen < 1) & (LastTritium >= GS3StorageCache["Tritium",number]) & (PctTritium > 0.1) ) {
Trit_Inverter_On = 1
}
if ((PctWater < 1) & (LastMethane >= GS3StorageCache["Methane",number]) & (PctMethane > 0.1) ) {
Meth_Inverter_On = 1
}
if ((PctNitrogen < 1) & (LastDeuterium >= GS3StorageCache["Deuterium",number]) & (PctDeuterium > 0.1) ) {
Deut_Inverter_On = 1
}
Trit_Collector_On = (PctOxygen < 1) | (PctTritium < 1)
Meth_Collector_On = (PctWater < 1) | (PctMethane < 1)
Deut_Collector_On = (PctNitrogen < 1) | (PctDeuterium < 1)
Thanks in advance,
Kevin
-
Untested, but I think something like this might work:
Target = 1
Hit = PctResource
Error = Target - Hit
if((Error <= 1 && Error > 0) && PctResource <= .1){
InverterOn = 1
} else {
InverterOn = 0
}
-
Here's what I am currently using. It may not be optimized, but I believe it works.
if (PctOxygen < 1) {
if ((!TritCharging) & (PctTritium < 0.1)) {
Trit_Inverter_On = 0
TritCharging = 1
} elseif (PctTritium == 1) {
Trit_Inverter_On = 1
TritCharging = 0
}
} else {
Trit_Inverter_On = 0
}
Trit_Collector_On = (PctOxygen < 1) | (PctTritium < 1)
-
Maybe just another late night oversight...
Any ideas on why this doesn't work?
Probe is the Atmospheric Probe
CAF is the Resource Cache with Energy, Oxygen, Water, Nitrogen, etc..
@name Terraform_v1.1
@inputs Probe:wirelink CAF:wirelink
@outputs
@persist
if (first() | duped()) {
runOnChat(1)
}
LastSaid = owner():lastSaid():lower():explode(" ")
Arg1 = LastSaid[1,string]
Arg2 = LastSaid[2,string]
Arg3 = LastSaid[3,string]
if (Arg1 == "!vent") {
if (Arg2 == "amount") {
print("Arg3 = :" + Arg3 + ":")
if (Arg3 != "") {
CAF["Vent Amount", number] = clamp(Arg3:toNumber(),0,1000000)
}
print("Vent Amount = " + CAF["Vent Amount", number])
}
}
The value is correctly set if I type !vent amount 1000 and it outputs Arg3 = :1000:
When I type !vent amount it should return the current value of Vent Amount from the CAF Storage Cache, but instead all I ever get is Vent Amount = 0
-
You're missing an else.
-
Hmm i don't think so, since I want to see that value for either case. But I think I could move that last print statement outside of that bracket. I'll try it and let you know. Thanks for looking.
Notice I also used the clamp() statement that I learned from you :)