Comparator actor behaviour ?
-
A clean fix using Javascript actor.
function debug(printString) { if (DebugMode){ print(printString + "\n"); } } function main() { DebugMode = true; op = parseInt(arguments[0]); // op 1, lessthan // op 2, greaterthan in1 = parseFloat(arguments[1]); in2 = parseFloat(arguments[2]); debug("1= " + in1 + " 2= " + in2); if (op === 1){ if (in1 < in2) { opOut = 1; debug("out1= " + opOut); }else{ opOut = 0; debug("out2= " + opOut); } } if (op === 2){ if (in1 > in2) { opOut = 1; debug("out1= " + opOut); }else{ opOut = 0; debug("out2= " + opOut); } } outVals = [opOut] debug("vals= " + outVals ); return outVals; }
The attached file shows how I set this up. The above Javascript goes into the JavaScript actor... its basic and needs expanding, but it works. ( @Michel seems like I can't format the Javascript code anymore.. and HTML view auto extends so you can't make edits.)
-
@DusX
Nice!
-
I was surprised that this worked, since I believed that the Javascript would run each time a value arrives,but in fact it seems that all values received during the cycle are used. Is this correct?If so it makes for an easy way to trap incoming values for a synchronized process. -
This javascript version produces the same behaviour as the comparator actor for me - sending two values from random value actors both triggered from a single actor produces the intermediate result when the first input has changed, and the final result when the second input changes.
-
I would use this to give single trigger when both are changing 'simultaneously'. The short delay means the intermidaite value gets lost.
The value on the trigger can be adjusted to a longer delay if it is unreliable. The final comparator can be omitted if you just want the value 0 or 1 from the comparison - it is there to recreate the true false triggers.Nick -
Strange. I expected the js to behave the same. I expected to have to add some logic to require both values be new. ( or like) But I couldn't see any double outputs.
-
Heres monitor output generated - first set of zeros created by changing value 2 to zero (1 was aready set to 0) - so just one output as only 1 input changed.
Then clicked on trigger value at top once which generates the next two sets, where the intermediate 'incorrect' value appears.The final two sets of values (where nothing changes) are generated by changing the value of input 1 from 1 to 2 -
Ok. Well that's really what it should do... I just hadn't noticed and thought it served the purpose. I will write a version that works.. Using the simultaneous actor to trigger the action.
-
@ dusX : I don't know yet how to use javascript but you're caught my attention. I puts me as possible !
@ nick : I return integrate your solution in my rectangle generator and I post the patch right here very soon
@ danshorten : your patch are true but not very stable on result for me . i just keeping searching.A big thanks to all for your help and your efficiency.
nZo
-
Dear All,
Well, it seems pretty clear that I need to address this in the actual Comparator actor. The behavior isn't intuitive in the case cited here.Best,Mark