Showing Variable Values on Screen

edited October 2014 in How To...

Hello Everyone I know that print() will show a value or a string in the console...

I understand that text() will print strings of text on screen....

But I haven't find documentation or examples on how to show values of a variable on screen (ie. a score in a game).

Any ideas?

Thanks in Advance!

Answers

  • It's very simple.

    Suppose you have an integer variable, named x.

    So your code would look somewhat like this:

    int x = 5;
    
    void setup() {
        size(300, 300);
    }
    

    Ok. Cool. So now, you want to show the value of the variable. The way that is done is to treat your variable just like a string of text. In Processing all the data type complexity has been done for you, so don't worry about that right now.

    The code will now, depending on how you write it, should have a text() call. Specifically:

    int x = 5;
    
    void setup() {
        size(300, 300);
    }
    
    void draw() {
        background(128);
        text(x, 20, 20); //Here's the text call.
    }
    

    The program above will work. Pretty much, when using the text() method, just replace the imaginary string inside the text method, and replace it with your variable name.

  • Thanks a bunch! I appreciate it

Sign In or Register to comment.