04-08-2022 02:43 PM
Creating two boolean scalars of
0,1,0,1,0,1,0,1... and 0,0,1,1,0,0,1,1...requires a For loop inside a While loop, a bunch of orange wires and select 1 duplications (Because maybe the first if True select 1 was ignored?) and dynamic data conversion
NOTE: only the first element out of the DDT conversions is actually used!
Or, we could use
There are a few other problems with the code provided.
04-08-2022 03:17 PM
@altenbach wrote:
Also, the division&multiplication could be done with one multiplication and a better constant. :D.
I have been known to be guilty of this (though I do use a compound arithmetic node when I do) because it can make the code more self-documenting. This would be for cases where, for instance, I have a constant which would be recognizable to me or future programmers along with a scaling factor which might obscure the constant.
04-08-2022 04:47 PM - edited 04-08-2022 04:48 PM
@johntrich1971 wrote:
@altenbach wrote:
Also, the division&multiplication could be done with one multiplication and a better constant. :D.
5.6
I have been known to be guilty of this (though I do use a compound arithmetic node when I do) because it can make the code more self-documenting. This would be for cases where, for instance, I have a constant which would be recognizable to me or future programmers along with a scaling factor which might obscure the constant.
I commonly will pull as much as possible out of the "data" line and let the Constant Folding handle the actual constant. As you said, it helps document what is happening. So in this example, I would have 1000/5.6 and multiply that result by the measured value.
04-08-2022 04:55 PM
@johntrich1971 wrote:
This would be for cases where, for instance, I have a constant which would be recognizable to me or future programmers along with a scaling factor which might obscure the constant.
Yes, with constant, I meant a "constant", i.e. explicit 1000/5.6 constant folded and even pulled out of the loop.
Still, I suspect that the compiler will actually figure out the sequence of multiplicative operations with constants and reduce it to one operation. In this case it is more about readability.
04-08-2022 07:53 PM - edited 04-08-2022 07:57 PM
@altenbach wrote:
@johntrich1971 wrote:
This would be for cases where, for instance, I have a constant which would be recognizable to me or future programmers along with a scaling factor which might obscure the constant.Yes, with constant, I meant a "constant", i.e. explicit 1000/5.6 constant folded and even pulled out of the loop.
Still, I suspect that the compiler will actually figure out the sequence of multiplicative operations with constants and reduce it to one operation. In this case it is more about readability.
At witch point, working back, the constant 5.6 should have been labled Ohms and the wire (or terminal) labled mVolts .
OR, drumroll~~~~~~~~~~~~ show Units and the 1000mAmps/Amp constant disappears. 🙄
04-10-2022 04:14 PM - edited 04-10-2022 04:15 PM
So we need to simulate a system with a water tank, two pressure sensors, two faucets, and two booster pumps, all interacting with each other simultaneously. (see here)
Apparently we need a mile long sequence structure where each frame contains a loop (100ms per iteration) to deal with exactly one component until some conditions are satisfied. Most values shuffled around with a liberal helping of local variables and value property nodes.
(scaled to 50%)
04-20-2022 12:29 PM
Holy code duplication batman! (Yes, the picture only shows the tip of the iceberg. The FOR loop is actually about 3x higher. 😄 )
I want to see the code once he has to deal with failures numbered from 1..1024!
04-21-2022 10:18 AM
Somebody revived an ancient thread, so let's look at some of the 20+ year old code :
(For example the code posted here)
Wile the entire code is quite horrible, here's the section that tests if elements at index 1, 2, 3, 4 are all empty strings.
(below I show a possible alternative)
04-22-2022 03:24 AM
I keep wandering if there is a reason to put those constants outside the loop.
I don't think it's faster (anymore)? Is this just habit? Or preference?
I personally prefer the constants inside the loop... Not looking for a flame war, just curious.
04-22-2022 04:56 PM
Makes no difference. I prefer constant outside because there is typically more diagram space there. In this particular case, the subset operation can be closer to the edge, allowing a shorter loop. 😄
Many times I add labels (left) to the constants, making them even wider. Once we have all labeled constant near each other, it is easer to make changes than to look for them all over the diagram. Often, the same constant is used in several places, so I just follow the wire. 😄