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 Problems.
Page Index Toggle Pages: 1
String Comparison Problems. (Read 964 times)
String Comparison Problems.
Jun 12th, 2005, 11:55pm
 
I am porting over some L-system classes from ActionScript to Processing (91) and am having some strange problems with string comparison.

Please forgive the slopiness of some of this code. It has all been written today.

So, I have an L-system class:

Code:

class Lsystem {

 String axiom;
 int rc, rm, renderindex, rint;
 String[] sa;
 RuleSet ruleset;
 Engine eng;
 Lsystem(String axiom) {
   this.axiom = axiom;
   this.rc = 0;
 };
 
 void registerRuleSet(RuleSet rs) {
   this.ruleset = rs;
 };
 
 void registerEngine(Engine e) {
   this.eng = e;
 
 };
 
 void recurse(int maxi) {
   this.rm = maxi;
   this.rc ++;
   
   this.sa = this.axiom.split("");
   String[] ta = new String[1000];
   
   for (int n=1; n<this.sa.length; n++) {
     String replace = this.ruleset.runRule(this.sa[n]);
     ta[n] = replace;
   };
   
   //print(ta);
   if (this.rc < this.rm) {
     this.recurse(this.rm);
   }
   else {
     this.rc = 0;
   };
 };
};


Which uses a RuleSet class to store sets of rules:

Code:


class RuleSet {

 Rule[] rules;
 int rulecount, test;
 
 RuleSet() {
   rulecount = 0;
   Rule[] temp = new Rule[100];
   rules = temp;
 };
 
 void init() {
 
 };
 
 void addRule(Rule r) {
   rulecount ++;
   rules[rulecount] = r;
 };
 
  String runRule(String rid) {
     for (int i=1; i<rulecount; i++){
       if (rules[i].id == rid) {
         println ("*******RUN RULE" + rid);
       };
     };
     return ("X");
  };
};



Code:

class Rule {
 String id;
 String[] rules;
 Rule(String name, String[] ruleset) {
   id = name;
   rules = ruleset;
 };
};


The problem is here:

Code:

String runRule(String rid) {
     for (int i=1; i<rulecount; i++){
       if (rules[i].id == rid) {
         println ("*******RUN RULE" + rid);
       };
     };
     return ("X");
  };


I am passing in an id value (ie. "X") and am looking through the array of rules for find a rule with the matching id property.

If I trace the two values out, I get this:

X:X

But, they are not satisfying the equality condition. If I convert them to char values first, I get this:

[C@c92535 : [C@a9c09e

Clearly these two values aren't equal... but for the life of me I can't figure out why.

Anyone have any idea why this might be?

Re: String Comparison Problems.
Reply #1 - Jun 13th, 2005, 12:42am
 
i don't analysed in depth your code, but in http://processing.org/faq/bugs.html there's an issue about different mode of comparing strings between AS and PDE.
_f
Re: String Comparison Problems.
Reply #2 - Jun 13th, 2005, 1:23am
 
Thanks.

I fixed that part of it.

Still more problems, but they're all mine.
Page Index Toggle Pages: 1