Trouble running a Processing.pde through Processing.js

edited January 2014 in JavaScript Mode

Hi,

I am relatively new to Processing. I am currently creating a simple map system allowing the user to selecting components / locations on a map. I then simply use the data the user has entered as input to another system. (I basically store it in a database for later use)

The user can select a bunch of points on my map, and then decide to unselect a few points. While, the unselecting code works fine in Processing, it doesn't run as expected in Processing.js. I get an error saying undefined integer thrown at me at times, and at other times, my input points are no longer drawn.

This is my code:

     if(!selectedVertices.equals("") && vertices[i].isSelected())
    {
      if(i > 0)
        vertices[i].unchoose();  //unselect this vertex      
      String[] s_vert = splitTokens(selectedVertices,",");
      selectedVertices = "";
      boolean flag = false;      
      int len_sel = s_vert.length;
      int j = (int)0;
///The program prints this
      println("Array length :"+ len_sel + " Unselecting at "+i+"    "+s_vert); 

      for(j =(int) 0; j < len_sel ; j = j + 1)
      {
///This is not being printed
        print("\t Index "+j);
        String sv = s_vert[j];     
        if(sv.equals(str(i)))
        {
          flag = true;
        }
        if(flag)
        {
          int s_v = Integer.parseInt(sv);
          if(s_v > 0)
            vertices[s_v].unchoose();   
        }
        else
        {
          if(selectedVertices.equals(""))
            selectedVertices = sv;
          else
            selectedVertices = selectedVertices +  "," +sv;
        }
      }
    }

The original input of the user is store in the selectedVertices string like so: "23,45,12,1,10,19" IF user unselects any entry in the middle of this string, for example "12", all the points selected from "12" are unselected and the selectedVertices should later contain only "23,45". But, I notice that while the first print statement is getting executed, the second one is not.

AM i missing something? I appreciate your help!

I suspect that it is to do with the loop variable : j. I have checked my code, I do not use "j" anywhere else. And once this error is reached, the application no longer accepts input!!!

Thanks!

Answers

  • Answer ✓

    Integer.parseInt(sv) might be the culprit. It is Java-specific, and Processing offers the int(sv) syntax to replace it.

  • Thanks! That worked!

  • Answer ✓

    Line 16 should be println() instead of print().

  • edited January 2014 Answer ✓

    @mbraendle print() is OK here, as the values are tab-separated. It saturates less the console, perhaps, and it is easier to browse. Supposing that both print() and println() are supported in Processing.js.

  • Answer ✓

    In my Processing.JS experiences, print() is always ignored! Only println() works! :)]

  • I noticed that print is ignored as well.

    I'd like to know if you face issues with Processing.js. It works say for the first test, but may not do so on subsequent tests. Also, is there any way i can debug Processing.js?

  • edited January 2014 Answer ✓

    Well, in Firefox & Chromium, I press together SHIFT+CTRL+J to open a JS console of sorts. =:)
    Other browsers like QupZilla and Midori, Change J to I.

Sign In or Register to comment.