Quantcast
Channel: Processing Forum
Viewing all articles
Browse latest Browse all 1768

Refresh displayed text based on condition?

$
0
0
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()

  1. import processing.serial.*;
  2. Serial port;
  3. PFont f;

  4. void setup() {
  5.   size(640, 360);
  6.   port = new Serial(this, "COM3", 9600);
  7.   port.bufferUntil('\n');
  8.   f = createFont("Arial",16,true);
  9. }

  10. void draw() {
  11.   background(0);
  12.   
  13.   int i=0;
  14.   int temp=-1;
  15.   int lastLogin = 0, lastLogout = 0;

  16.   String[] lines = loadStrings("C:/McMyAdmin/Minecraft/plugins/BeardStat/stats.yml");
  17.   
  18.   println("there are " + lines.length + " lines");
  19.   
  20.   String searchLogin = "stats-lastlogin";
  21.   while(i < lines.length){
  22.     int index = lines[i].indexOf(searchLogin);
  23.     if(index >= 0){
  24.       String sub1 = lines[i].substring(index+17);
  25.       //println(sub1);
  26.       lastLogin = int(sub1);
  27.     }
  28.     i++;
  29.   }
  30.   
  31.   i=0;
  32.   
  33.   String searchLogout = "stats-lastlogout";
  34.   while(i < lines.length){
  35.     int index = lines[i].indexOf(searchLogout);
  36.     if(index >= 0){
  37.       String sub2 = lines[i].substring(index+18);
  38.       //println(sub2);
  39.       lastLogout = int(sub2);
  40.     }
  41.     i++;
  42.   }
  43.   
  44.   textFont(f,16);
  45.   fill(255);
  46.   
  47.   if(lastLogin < lastLogout){
  48.     println("User is logged out.");
  49.     port.write(0);
  50.     text("User is logged out.", 10, height/2);
  51.   } else {
  52.     println("User is logged in.");
  53.     port.write(1);
  54.     text("User is logged in.", 10, height/2);
  55.   }
  56.   
  57.   myDelay(5000);
  58. }

  59. void myDelay(int ms){
  60.   try{    
  61.     Thread.sleep(ms);
  62.   }
  63.   catch(Exception e){}
  64. }


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?

Viewing all articles
Browse latest Browse all 1768

Trending Articles