Loading...
Logo
Processing Forum
Just a couple of quick questions: First, I keep getting the error  "unexpected char: '\'" when I try and run this piece of code:

Copy code
  1. PVector position, velocity;
  2. int diameter;
  3. void setup(){
  4. size(500,500);
  5. background(0);
  6. smooth();
  7. position = new PVector(10,10,0);
  8. velocity = new PVector(3,5,0);
  9. diameter = 10;
  10. }

  11. void draw(){
  12. background(0);
  13. position.add(velocity);
  14. bounceWalls();
  15. noStroke();
  16. fill(255);
  17. ellipse(position.x,position.y,diameter,diameter);
  18. }

  19. void bounceWalls(){
  20. float leftLimit, rightLimit, upperLimit, lowerLimit;

  21. leftLimit = diameter*.5;
  22. rightLimit = width–diameter*.5;
  23. upperLimit = diameter*.5;
  24. lowerLimit = height – diameter*.5;
  25. if(position.x < leftLimit)
  26. {
  27. position.x = leftLimit;
  28. velocity.x = velocity.x*-1;
  29. }
  30. if(position.x > rightLimit)
  31. {
  32. position.x = rightLimit;
  33. velocity.x = velocity.x*-1;
  34. }
  35. if(position.y < upperLimit)
  36. {
  37. position.y = upperLimit;
  38. velocity.y = velocity.y*-1;
  39. }
  40. if(position.y > lowerLimit)
  41. {
  42. position.y = lowerLimit;
  43. velocity.y = velocity.y*-1;
  44. }
  45. }
With the IDE highlighting line 26. As you can see, there isn't a backslash on that line, so the only problem I can think of is that my IDE is a bit wrong, or there is some strange and mystical invisible backslash character somewhere in there. I've had it happen on multiple projects, but this one just annoyed me enough to post.

Second question: Is there a way to resize the processing window or applet, without changing the pixels, as it were? Like a window 600x300 px, but processing drawing lines and all in a 300x150 grid of pixels at the 600x300 px window size? I want to try and make a pixel-ly game, but don't know if I have to introduce extra code to achieve this.

Thanks in advance!

Replies(6)

Hi
I get those funnies now and then. I've copied your code and got the same error message when I ran it. I then commented out those two lines (it happens again later on) and completely retyped them. Now I see your circle bouncing around the stage.
string
Thanks! That's strange, though. So is it a bug in the IDE, or just a invisible typing error? Do you have any idea on the other question?
hi,

the problem with your code is the "minus"-sign.
run the following code, to see the difference


Copy code
  1. char c1 = '–'; // this is the minus of your code
  2. char c2 = '-'; // this is the minus that works as a real minus
  3. int c1_as_integer = c1;
  4. int c2_as_integer = c2;
  5. println("c1 '"+c1+"' as integer = " + c1_as_integer );
  6. println("c2 '"+c2+"' as integer = " + c2_as_integer );
So how have rialobran and I managed to get emdashes rather than endashes into our code? I don't have one on my keyboard and would have to look up the ascii code to use one.
For me it was because I was using example code. Perhaps you could see if you could map the different key to it?
If you replace all of your heights with 150s, then yes. (Or maybe just create new variables altogether.)
Like SW for width and SH for height, because they're really easy to type.
Or you could completely disable drawing to the lower portion by calling frame.setSize(600, 300); after declaring size as having the dimensions of 600 by 150.