loadStrings() is not working properly

edited March 2018 in Questions about Code

I'm messing around loadString(), but i run into a problem what i don't really understand why happened.

Only code 4 runs even if in the file.txt at the l line there is FUNC1 , FUNC2 or FUNC3.

        String[] file;
        int l = 0;
        void setup() {
          file = loadStrings("file.txt");
        void draw() {
          if(l < file.length) {
            if(file[l] == "FUNC1"") {
              //code 1
            }else if(file[l] == "FUNC2") {
              //code 2
            }else if(file[l] == "FUNC3") {
              //code 3
            }else {
              //code 4


  • edited March 2018 Answer ✓

    you have to use equals instead of == with Strings

    if(file[l].equals( "FUNC1" ) ) {

    no double "" please

  • int l = 0; is a very bad variable names since it looks likes 1 (one).

    in fact all variable names with length one are bad, except maybe x,y, i

    variable names start with a small letter like i or index

    constants BIG_LETTERS

    classes big Capital, like class Ball

    arrays and ArrayList small but plural like balls

  • Thanks for the fast and useful help. :)

Sign In or Register to comment.