Refresh displayed text based on condition?
in
Core Library Questions
•
7 months ago
Hi everyone, I've only just started using Processing today so i'm a bit stumped on this..
I'm trying to display whether a user is online or offline by using text(). I have two different methods, either one printing based on a condition, but when that condition changes, the text does not. I'm getting a readout in the console so I know that the condition statement is switching, but the displayed text isn't..
Here's the code - you can find the text methods towards the end of draw()
- import processing.serial.*;
- Serial port;
- PFont f;
- void setup() {
- size(640, 360);
- port = new Serial(this, "COM3", 9600);
- port.bufferUntil('\n');
- f = createFont("Arial",16,true);
- }
- void draw() {
- background(0);
- int i=0;
- int temp=-1;
- int lastLogin = 0, lastLogout = 0;
- String[] lines = loadStrings("C:/McMyAdmin/Minecraft/plugins/BeardStat/stats.yml");
- println("there are " + lines.length + " lines");
- String searchLogin = "stats-lastlogin";
- while(i < lines.length){
- int index = lines[i].indexOf(searchLogin);
- if(index >= 0){
- String sub1 = lines[i].substring(index+17);
- //println(sub1);
- lastLogin = int(sub1);
- }
- i++;
- }
- i=0;
- String searchLogout = "stats-lastlogout";
- while(i < lines.length){
- int index = lines[i].indexOf(searchLogout);
- if(index >= 0){
- String sub2 = lines[i].substring(index+18);
- //println(sub2);
- lastLogout = int(sub2);
- }
- i++;
- }
- textFont(f,16);
- fill(255);
- if(lastLogin < lastLogout){
- println("User is logged out.");
- port.write(0);
- text("User is logged out.", 10, height/2);
- } else {
- println("User is logged in.");
- port.write(1);
- text("User is logged in.", 10, height/2);
- }
- myDelay(5000);
- }
- void myDelay(int ms){
- try{
- Thread.sleep(ms);
- }
- catch(Exception e){}
- }
EDIT - I have not noticed that if I leave it run for a while, the text does eventually update, but not instantly. The console messages do change instantly though, so it it something to do with loading the text?
1