If/Else Statement Error with ofQTKitPlayer and ofSerial


For some reason my sketch is not stepping into the “else if” statement on line 99: http://pastebin.com/wQnCApNz.
The sketch jumps down to line 147 and so the variable int cue is always 11. Is this a memory issue?

The code I am testing with is clunky and I had been using a pointer. I had this format implemented successfully once before, but with ofVideoPlayer and only 5 paths. Could the number of videos be the issue. Here is the github where I have all the versions as different branches: https://github.com/Queeniebee/THREADBARE_v1/blob/versionQT3/src/ofApp.cpp.

Thank you,


don’t use the compariso equal to operator (==) on floating-point values. You can never be sure the computer stores floats/doubles exactly the same as you think it is to you. That’s why none of your == statements return 1 to launch the setting of the cue variable.

If you really want to test floats, it’s better to do for instance:

if (oldShaderValue < 0.85 && oldShaderValue > 0.75) ...

However, since your oldShaderValue * 100 always gives a nice int, you could create a temporary int test value as following. I also switched to a switch/case because I find this better reflecting the logic.

int testVal = (int) (oldShaderValue * 100);

      switch ( testVal ) {
      case 8:
            cue = 1;
      case 16:
            cue = 2;

            cue = 11;

      cout << "cue: " << cue << endl;

Best, V

Hi V,

I have oldShaderValue set to shaderValue * 100 as you suggested, but it is still not being compared to the int values.

I am using breakpoints in XCode and oldShaderValue is being set properly but the sketch finds all of the (else if) statements false.

Int cue=0;
Int oldShaderValue = 0;
Int intShaderValue = shaderValue * 100;

If(oldShaderValue != intShaderValue){
oldShaderValue = intShaderValue;
If(oldShaderValue == 35){
cue = 0;} else if(oldShaderValue == 70){ cue = 1;} else if (oldShaderValue == 85){ cue == 2;}

I am only including a snippet because I am typing from my phone, but the of/else remains the same from the link