random_switch not working as expected
Posted: 03 Sep 2024 23:05
In an industry NewGRW, I have one incoming cargo and I want to produce one (and only one) outgoing cargo out of a selection of three at each delivery.
My example is a recycling depot which receives RFPR and should either produce PAPR, POLY, or FERT selected at random - with a new selection for each turn.
However, the following code compiles correctly with the latest nmlc version but does not give the desired result, as only one cargo is produced - any ideas of what's wrong with it? Unfortunately, seems like there are not many code examples around and this was adapted directly from the documentation.
My expectation would be that in two out of four deliveries, POLY would be produced and in 1/4 of each deliveries, either FERT or PAPR.
My example is a recycling depot which receives RFPR and should either produce PAPR, POLY, or FERT selected at random - with a new selection for each turn.
However, the following code compiles correctly with the latest nmlc version but does not give the desired result, as only one cargo is produced - any ideas of what's wrong with it? Unfortunately, seems like there are not many code examples around and this was adapted directly from the documentation.
My expectation would be that in two out of four deliveries, POLY would be produced and in 1/4 of each deliveries, either FERT or PAPR.
Code: Select all
produce(recycling_yard_produce_3,
[RFPR: LOAD_TEMP(1);], // consume
[FERT: LOAD_TEMP(1);], // produce
0 // don't run
)
produce(recycling_yard_produce_2,
[RFPR: LOAD_TEMP(1);], // consume
[POLY: LOAD_TEMP(1);], // produce
0 // don't run
)
produce(recycling_yard_produce_1,
[RFPR: LOAD_TEMP(1);], // consume
[PAPR: LOAD_TEMP(1);], // produce
0 // don't run
)
random_switch(FEAT_INDUSTRIES, SELF, produce_recycling_yard_2) {
1: recycling_yard_produce_1;
2: recycling_yard_produce_2;
1: recycling_yard_produce_3;
}
switch(FEAT_INDUSTRIES, SELF, produce_recycling_yard_1, [
STORE_TEMP(incoming_cargo_waiting("RFPR"), 1),
])
{
produce_recycling_yard_2;
}
switch(FEAT_INDUSTRIES, SELF, produce_recycling_yard_0, incoming_cargo_waiting("RFPR") < 1)
{
1: produce_none;
produce_recycling_yard_1;
}