| Author |
Message |
christorb

Joined: Feb 09, 2010 Posts: 17 Location: Cambridge, UK
|
Posted: Tue Feb 09, 2010 6:09 am Post subject:
syntax error??! |
 |
|
Hi all, I'm just getting started with ChucK as an audio and technology student at uni. I've been using miniAudicle but I've run into a problem...
I'm literally going through the online tutorial and typing in the code, however when I try to run the patch I'm being told that there's a syntax error on line 2 char 1. As far as I can tell there's nothing wrong with it.
All I'm trying to run is this piece of simplicity:
1. SinOsc s => dac
2. while( true )
3. {
4. 2::second => now;
5. }
Whenever I run the examples that came with miniAudicle they work without a hitch, so I really don't understand what the problem is! In fact, whenever I use the line 'while( true )' in any patch I'm writing myself I get a syntax error from it, but like I said, if I've loaded up an example with that line in it it just seems to work!! Am I missing something obvious here?
Cheers guys,
Chris |
|
|
Back to top
|
|
 |
Inventor
Stream Operator

Joined: Oct 13, 2007 Posts: 6221 Location: near Austin, Tx, USA
Audio files: 270
|
Posted: Tue Feb 09, 2010 6:33 am Post subject:
|
 |
|
Hi and welcome to the forum. You need a semicolon at the end of line 1. The console window will report the following line number when you leave out a semicolon for some reason, and this is common to every semicolon-deliniated language that I have ever programmed.
Don't feel foolish, I'm a fairly experienced programmer and have been coding ChucK for over two years, yet I occasionally make this same mistake!
Les _________________ "Let's make noise for peace." - Kijjaz |
|
|
Back to top
|
|
 |
christorb

Joined: Feb 09, 2010 Posts: 17 Location: Cambridge, UK
|
Posted: Tue Feb 09, 2010 6:49 am Post subject:
|
 |
|
Ah, that was exactly it! Thanks for the reply - though I feel kind of stupid now :S!! I got so hung up on the second line that I wasn't paying attention to anything else!
Many thanks again, now onwards with ChucK  |
|
|
Back to top
|
|
 |
blue hell
Former site admin

Joined: Apr 03, 2004 Posts: 24864 Location: The Netherlands, Enschede
Audio files: 353
G2 patch files: 320
|
Posted: Tue Feb 09, 2010 1:30 pm Post subject:
|
 |
|
| Inventor wrote: | | The console window will report the following line number when you leave out a semicolon for some reason |
No ... but the compiler will report on the first occasion that it can actually detect the error .. for instance try what happens if you put two statements on the same line forgetting the semicolon in between ... white space usually is allowed before the semicolon, so the line end is not an error ... that would be the reason. |
|
|
Back to top
|
|
 |
Kassen
Janitor


Joined: Jul 06, 2004 Posts: 7678 Location: The Hague, NL
G2 patch files: 3
|
Posted: Sat Feb 13, 2010 10:16 am Post subject:
|
 |
|
Indeed. And this is good as it can be useful to break up statements in code over several lines. This is a good idea for long statements that contain several more or less independent parts, for example more complicated "if" statements. Like this;
| Code: | if (foo == bar &&
baz < 10 &&
now > last_time)
{
do.stuff()
more.stuff()
} |
So, yes; strictly speaking the error *is* in the second line from the perspective of the parser as the second line doesn't relate to the first in the expected way.
At first this stuff might look more confusing that it really is and you'll get the hang of it. When using brackets and missing one the error can be reported as being quite a few lines away from where you needed the bracket to be. This takes a bit of experience to get used to. _________________ Kassen |
|
|
Back to top
|
|
 |
|