Classes that use string variables

edited May 2016 in Programming Questions

So I was programming this class and I needed to have a string var. inside so I could change on the main sketch.

I did exactly the same way I did all the other variables but now that I need to initialize it on setup() it never gets it started

numbers1 = new Numbers(100, 100, "string_here" , false, false);

and it doesn't matter what I put there, nothing works. (0, 'string_here', "string_here", string_here... I even tried calling the string var. inside the class or creating a new one outside the class to call) It always give me back this console warning that I'm not giving a (int, int, string, boolean, boolean) and it's missing a string.

This looks like one of those stupid easy mistakes, but I just can't see where is it.. Anyways, thanks for all the help.

Tagged:

Answers

  • The class Numbers doesn't have a constructor that accepts 5 parameters 2 ints followed by a string followed by 2 booleans e.g.

    public Numbers(int int1, int int2, String myString, boolean bool1, boolean bool2){
      // your code here to process the parameters
    }
    

    Can't be more specific without seeing the code for this class.

  • This is inside the Numbers class

    class Numbers
    {
    
      int xPos;
      int yPos;
      string displayNumber;
      boolean appear;
      boolean trash;
    
      Numbers(int tempxPos, int tempyPos, string tempDisplayNumber, boolean tempAppear, boolean temptrash)
      {
        xPos = tempxPos;
        yPos = tempyPos;
        displayNumber = tempDisplayNumber;
        appear = tempAppear;
        trash = temptrash;
      }   
    
      movement()
      {
        fill(40);
        textSize(48);
        pushMatrix();
    
        translate(xPos, yPos);
    
        text(displayNumber, 2, 5);
        fill(0);
        text(displayNumber, 0, 0);
    
        if (trash == true)
        {
          yPos = (yPos - (yPos/20)) - 5;
        }
    
        popMatrix(); 
      }
    
    }
    

    and this is on the main sketch where I initialize it

    Numbers numbers1;
    
    void setup()
    {
    ...
    numbers1 = new Numbers(100, 100, str1 , false, false);
    }
    

    I have other 2 classes in this same sketch all made the same exact way working fine. But this one using string simply can't be initialized.

    p.s.: I just took the not related code from the setup() to make it easier to read.

  • edited June 2014 Answer ✓

    you must write string with a capital S as String

    line 6 and 10

    ;-)

  • this line looks correct:

    numbers1 = new Numbers(100, 100, "string_here" , false, false);
    
  • when the class Numbers represents only one number (it looks like) you might call it

    class Number in singular

  • haha, yes! it works now (such a dumb mistake) Thanks again, this forum rocks.

  • Sure! ;-)

Sign In or Register to comment.