Loading...
Logo
Processing Forum
Has any1 been successful at running CS compiled code in newest Processing 2?

Tried both @ Chromium under Processing's local server and Firefox's directly running offline from disk.

P.S.: JS mode works alright!

A test sample:
Copy code
  1. # https://github.com/processing-js/processing-js/blob/master/processing.js#L2241
  2. # https://github.com/fjenett/coffeescript-mode-processing/issues/16

  3. setup: -> size 600, 400, JAVA2D; fill 0xffFF0000

  4. draw:  ->
  5.   background -1
  6.   text "#{frameCount} - ", 100, 100

Replies(16)

In CS, whitespace is significant.  The only thing that delineates one line of code from another is the carraige return, and the only thing that delineates a block of code is an indent of an equal number of spaces.  Although you can use semicolons, one of the purposes in CS is to not have to use them.  If you do use semicolons, you cannot use them to keep a few lines of code on the same line.  You can only use them at the end of one line followed by a carriage return.

Try this (works for me):
Copy code
  1. setup: -> 
  2.       size 600, 400, JAVA2D
  3.       fill 0xffFF0000

  4. draw:  ->
  5.       background -1
  6.       text "#{frameCount} - ", 100, 100
Also, unless you have a specific reason to, I don't think you need to use JAVA2D since there won't be any java anything used.  The default will be 2D.

[EDIT: please read updates below, some information contained in this post was later proved incorrect by myself]
UPDATE:  I'm not entirely sure why it doesn't work actually.  I took a look at it in js2coffee.org and it compiles the same way.  Additionally, if you look at the yourSketch-compiled.js, it appears to be compiled correctly.  Still, writing CS in the traditional way will make it work in CS mode.
UPDATE:  okay okay.  i hadn't copied your code correctly into js2coffee.org.  your problem is the lack of carriage return on the setup function.  i was incorrect about the semicolons on the same line; you can write more than one line of code separating them by semicolons.

the following will work:
Copy code
  1. setup: -> 
  2.       size 600, 400, JAVA2D; fill 0xffFF0000

  3. draw:  ->
  4.       background -1
  5.       text "#{frameCount} - ", 100, 100
MORE UPDATES!

alrighty.

so.

i *did* input it correctly into js2coffee.org, and all the versions (yours, mine #1, mine #2) all compile the same.

however!

the key can be found when you take a look at yourSketch-compiled.js in firebug/web inspector.

for reasons beyond my pay grade, when you do not use a carriage return after setup, the Processing API is not injected.  (FYI: the Processing API is injected after setup).

w/o carriage return:

w/ carriage return:
Maybe the compiler is looking for "setup: -> [carriage return]" to inject the API as opposed to just "setup ->"

This proves once again Florian Jenett's (CS (and JS) Mode creator) maxim: "Always, as in really always, if you run into trouble with your code look at the "YourSketchName-compiled.js" file that is loaded in the browser as your sketch." 
Oh, it worked!!! Thx a lot!  

It's just that it's my 1st time w/ Processing 2 as well. 
And trying to use an "unknown" mode as CoffeeScript was much ahead for me.
If you do use semicolons, you cannot use them to keep a few lines of code on the same line.
Well, your statement isn't correct!     Semicolons are obligatory 
when you put more than 1 statement in the same line!
It's the same rule to any C-like language. Even though CoffeeScript is more like Ruby + Python.

You can check that out yourself @ http://CoffeeScript.org/ 
and click @ -> Try CoffeeScript menu, where you can type real CS code!

What I haven't realized up till now is that CS Mode is still very precarious, 
and can't recognize code format as good as a real CS compiler!

And just found out another incompatibility:
I always have to use 2 spaces for each level of indentation throughout my code, 
since my tab default is 2 spaces here.

It means my source code won't compile in Processing's IDE w/ different tab space configuration!  

I hope these details can be overcome by the author of CS adaptation for Processing some time in the future!

Well, let's hope I can start converting some of my code examples to CS soon!  

P.S.: Seems like you did a lot of updates while I was writing this post!  
Yup.  I was incorrect about the semicolons.  You might have missed it as I was updating and you were writing.  See my third posting where I wrote:

"i was incorrect about the semicolons on the same line; you can write more than one line of code separating them by semicolons."

regarding the indentation, take a look at the following and see if that helps.  it worked for me.  however, i'm still using 2.0b9.


As far as the  precarious  nature goes, i've been using it to go through daniel shiffman's nature of code and other then a bunch of hiccups that were due to not understanding the order of events (namely, the API injection) it's been smooth since.  I'm on my third chapter.  There's been one other small issue with the boolean mousePressed.

Sorry about the constant updates.  I tried out my first solution which worked so I thought "solved!".  Then I thought of a few other tests.

"Always, as in  really always , if you run into trouble with your code look at the "YourSketchName-compiled.js" file that is loaded in the browser as your sketch."
I had looked @ generated compiled code. Problem is that I still haven't anything to compare that with!  
I had no idea about that ugly inserted code had to exist in the 1st place!!!

That was more to me for not having checked it in the first place therefore having to return 3 times before actually finding the root of the problem.
Seems like CS Mode accepts multi-statements in the same line separated by semi-colons anyways!

It's just what you said above:
...When you do not use a carriage return after setup, the Processing API is not injected...
So, it's just a little hiccup from CS Mode anyways!  

Here's a running code using multi-statements:
Copy code
  1. setup: ->  
  2.   size 600, 400, JAVA2D; fill 0xffFF0000; textSize `030`

  3. draw: ->  background -1; text "#{frameCount}", 100, 100
Now, I just wish that CS Mode allowed the use of something like #FF0000 webcode as well!  
Yes.  See 3rd update.  Passing ships in the updates as it were.  It would be nice if Zoho implemented live updates so you could have a notification when that happens.
oh, and yes.  it's a bit of a bummer that CS uses the hash for comments.  i'll send the creator a suggestion to update the readme if that is in fact the problem.  I tend to use RGB anyway so I hadn't experienced it yet.

Regarding the indentation, take a look at the following and see if that helps.
I had no problem w/ indentations for myself!

As I stated before, my worries lie that my source code become incompatible 
and can't be compiled by others due to indentation configuration!
That is, CS Mode is # of spaces dependent!
It's a bit of a bummer that CS uses the hash for comments.
I see no much problem at using # instead of //.  
Dunno what you mean by RGB though! I believe it's not about Red-Green-Blue comments, right?  

P.S.: Here's the article which informed me that Processing 2 was released!  

This forum haven't given out any sign about that news!  
hmmm.  I'm not following you on the indentations.  my understanding is that CS doesn't care how many indentations you use so long as it is consistent throughout your code (perhaps just consistent within a block, haven't tried).  you can even use 1 if you'd like   therefore your code would always risk being incompatible with other code that does not use the same number of indentations.  again, perhaps i'm not following what you are saying so i may need some clarification in understanding what you are getting at.

the response about the hash came out of context. sorry.  it was in reference to your issue with the fact that you could not use web codes such as #FF0000.  What I was trying to say was that when written is CS, fill #FFFFFF will compile to JS as just fill since the # signifies that it's a comment.  Therefore hex web codes can't be used.  I hadn't noticed it before because i always use RGB, fill(255, 0, 0).



My understanding is that CS doesn't care how many indentations you use so long as it is consistent throughout your code (perhaps just consistent within a block, haven't tried).
I perfectly know about that. We can use any number of spaces for indentation, 
as long it's consistent within a block!

But as I'm trying to say all along. CS Mode needs a fixed indentation throughout the code instead!

The number of spaces for indentation depends on what's configured in preferences.txt.
So it makes a CS Mode code format dependent on individual Processing's config to be able to compile!  

... fill #FFFFFF will compile to JS as just fill since the # signifies that it's a comment.
I was lazy to join the relationship about hash comment w/ web code! 
Also, CS uses #{} for code insertion into strings!

A pity web code format is outta our plates for CS!  
okay. i see what you're saying now.  just trying gain some clarity that's all.

yes.  the indentation issue isn't great for trying out other peoples code, and that will definitely get in the way when trying to help people or explore other people's work.  you should sign up for a github account so you can make a feature request.  it's free and you have a valid point.



side note:

regarding the exact issue you bring up about differing indentation settings in the IDE Florian writes in the readme:

"In any way, this will be messy and you will hate me for it.  Sorry!"

very funny (i think).