How to use loadMovie() with a variable filename

Hey! I am trying to load a movie each time a condition is triggered. I generate a random number, and then the videoplayer should load the movie that contains that number. Something like this:

 else if ( myByte > 130 ){
        float ranNumb = ofRandom(1, 5);
        int rounded = (int)ranNumb;
        cout << rounded << "\n";
        myPlayer.loadMovie("movies/testMovie_", rounded,".mp4");
    }

Obviously the last line does not work in C++/OpenFrameworks. I am used to Processing and there I would just use the “+” operator to combine the string with the rounded variable. How would I go about doing this?

Hi there!

In OF, you can still use +. But you have to convert your int to a string. Processing does it automatically. So, something like this:

myPlayer.loadMovie("movies/testMovie_" + ofToString(rounded)+ ".mp4");
2 Likes

Many thanks, that works!