We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › String comparison not working
Page Index Toggle Pages: 1
String comparison not working? (Read 626 times)
String comparison not working?
Jan 25th, 2010, 3:18pm
 
hello!  I'm fairly new to Processing, but have a lot of experience in programming in general, particularly in the NUI field.  I'm working on my first basic multi-touch app in Processing, using OscP5 to receive messages from CCV.  The messages are coming in OK, but for some reason, I'm unable to evaluate strings I'm getting from OSCArgument.stringValue();  Code below...

Code:
// Imports
import java.util.Vector;

import fashionbuddha.ui.Cursor;
import processing.core.PApplet;
import oscP5.*;

// Main class
@SuppressWarnings("serial")
public class Main extends PApplet {

// OSC listener
OscP5 OscListener;

// Cursor list
Vector<Cursor> CursorList;

// Initialization
public void setup() {

// Set up stage
background(0);
size(1024, 768);
frameRate(30);
smooth();

// Set up listener
OscListener = new OscP5(this, 3333);

// Initialize the cursor list
CursorList = new Vector<Cursor>();

}

// Draw
public void draw() {

// Set cursor fill color
fill(255, 192, 0);

// Iterate through existing cursors
int cursors = CursorList.size();
for (int i = 0; i < cursors; i++)
{

// Cursor marked for removal
if (CursorList.get(i).Remove)
{

// Remove the cursor
CursorList.remove(i);

}
else
{

// Draw cursor
ellipse(CursorList.get(i).X, CursorList.get(i).Y, 20, 20);

}

}

}

// Handle OSC messages
void oscEvent(OscMessage message) {

println(message.get(0).stringValue()); // "set"
println(message.get(0).stringValue() == "set"); // false, but should be true


// Looking for set message
if (message.get(0).stringValue() == "set")
{

// Get the cursor
Cursor cursor = new Cursor(
message.get(1).intValue(),
(int)(message.get(2).doubleValue() * (double)screen.width),
(int)(message.get(3).doubleValue() * (double)screen.height)
);

// Initialize variable for existing cursor
Cursor cursorInList = null;

// Iterate through existing cursors
int cursors = CursorList.size();
for (int i = 0; i < cursors; i++) if (CursorList.get(i).ID == cursor.ID) cursorInList = CursorList.get(i);

// Cursor exists
if (cursorInList != null)
{

// Update position
cursorInList.X = cursor.X;
cursorInList.Y = cursor.Y;

}
else
{

// Add the cursor
CursorList.add(cursor);

}

}

}

}



Any ideas?
Re: String comparison not working?
Reply #1 - Jan 25th, 2010, 3:30pm
 
Use equals() for String comparisons.

It's all explained in the docs Wink
Re: String comparison not working?
Reply #2 - Jan 25th, 2010, 3:40pm
 
Thanks!  Will look it up.  I'm finding that Java is nearly identical to C#, so I've essentially just been writing C# and hoping for the best.  Has actually worked well so far.
Page Index Toggle Pages: 1