help with writing serial code.

i have a peice code and i used

Serial.println( lscore)

and when it desplays the score it just keeps on updating it on a new line. which it should but is there a way the i could put Left Players score: xx Right Players score: yy and just have it update the "xx" and "yy" to what lscore and rscore is.

If you don't want a newline, use Serial.print () instead of Serial.println (). That will print the output and the next Serial.print/println call will append to that line instead of a new line.

Few things to consider...

[1] You'd format the command to get the text + score on the same line something like this

Serial.print("Left Players score: ");  
Serial.print(Left_score_value);
Serial.print("     ");
Serial.print(Right Players score: ");
Serial.println(Right_score_value);

[2] To clear the previous score, it depends on what you are "printing" to, for example are you viewing the output in the Arduino IDE, hyperterminal, processing, LCD, something else?

If you are using hyperterminal, there are clear line and clear screen commands you can send. You would do this just before sending the new score.

Look at the codes that move the cursor rather than printing spaces so that you don't over write what is printed already.

This is a throw back to how you used to code on glass terminals.

This is a throw back to how you used to code on glass terminals

Some of us are old enough to remember when it was a throwback to moving the clackety spinning print-head back to the left hand-side of the paper! ;D

A bit simpler than cursor codes (which are terminal specific): just use a carriage return ('\r' character) and re-write the entire line. A few spaces at the end of the line may be necessary if the score goes down (i.e. the whole line gets shorter).

e.g.:

Serial.print("Left Players score: ");
Serial.print(Left_score_value);
Serial.print("     Right Players score: ");
Serial.print(Right_score_value);
Serial.print("     \r");

-j

well yeah id rather it be like

Left player's score: 15 Right player's score: 15

then it would erase that line and replace it with

Left player's score: 30 Right player's score: 15

and so on. not like

Left player's score: 15 15 15 15 15 15 15 15 15 15 15 15 15 15 
15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 
15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 
15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 
15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 
15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15
15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 
15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 
15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 
15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 
15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 
Right player's score: 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 
15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15
15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 
15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 
15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15
15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 
15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15
15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 
15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 
15