[chuck-users] a little debugging help for frozen VM!

Andrew Turley aturley at acm.org
Fri May 25 15:57:16 EDT 2012


Your code never gets out of the first while-loop. Among other things,
that means that you never make it to the pedEvent handler. I'm not
entirely sure what you're trying to do, but I think you want something
more like this:

//begincode

Machine.add("justa.ck");                        //class of frequency definitions
Machine.add("pedestrianSender.ck");      //OSC sender of int values

OscRecv receiver;                                //OSC receiver object
6449 => receiver.port;
receiver.listen();
receiver.event("weather/pedestrian, int") @=> OscEvent pedEvent;

-1 => int b3base1;  //int to store a shred ID
-1 => int b3base2;  //ditto

25 => int pedCount; //int to store pedCount sent via OSC

while (pedEvent.nextMsg() != 0) {
  pedEvent.getInt() => pedCount;

  //if the pedCount is greater than 20 (a value which will be sent via
OSC) and b3base1 is equal to -1, i.e. the shred isn't currently
running,
  //add both shreds to the VM and assign their shred ID to the b3base1
and b3base2

  if (pedCount > 20 && b3base1 == -1) {
    Machine.add("b3base.ck") => b3base1;
    Machine.add("b3base.ck") => b3base2;
  }

  else {

    //if the pedCount is less than 20, remove both shreds from the VM
and assign -1 to their value so that if the pedCount goes back above
20 they
    //meet the conditional.

    if (pedCount < 20 && b3base1 != -1) {
      Machine.remove(b3base1);
      Machine.remove(b3base2);
      -1 => b3base1;
      -1 => b3base2;
    }
  }

  while( pedEvent.nextMsg() != 0) {
    pedEvent.getInt() => pedCount;
    2::second => now;
  }
}

//endcode

If you need to run through the loop once when you start then you could
use a do-while-loop instead of a while-loop
(http://chuck.cs.princeton.edu/doc/language/ctrl.html#while).

andy

On Fri, May 25, 2012 at 3:32 PM, [chriswicks] <crwicks at yahoo.com> wrote:
> Hey, all.  I'm attempting to build something that shifts layers of ChucK
> files based on OSC events, and I hit a snag really early on.  I'm a
> relatively new programmer, so hopefully this isn't too stupid of a question,
> but I've got an issue that freezes the virtual machine and doesn't play any
> sound or send any OSC events.  Nothing happens..the VM shows that the shreds
> are added, and then it just freezes and I have to force quit...it won't take
> a --removeall or --kill command or anything.  Individually, each file works
> as it should, aside from the file whose code I am including here.  I think I
> may be missing a key concept as to the way Machine.add works and how it
> assigns the value of the shred to an int, but I'm just not sure.  If anyone
> can give me some direction here as to what might be happening I'd appreciate
> it!  I've tried advancing time in various places, setting my initial
> pedCount to various values, all to no avail.  Thanks very much, and please
> let me know if this is unclear in any way.
>
> //begincode
>
> Machine.add("justa.ck");                        //class of frequency
> definitions
> Machine.add("pedestrianSender.ck");      //OSC sender of int values
>
> OscRecv receiver;                                //OSC receiver object
> 6449 => receiver.port;
> receiver.listen();
> receiver.event("weather/pedestrian, int") @=> OscEvent pedEvent;
>
> -1 => int b3base1;  //int to store a shred ID
> -1 => int b3base2;  //ditto
>
> 25 => int pedCount; //int to store pedCount sent via OSC
>
> while (true) {
>
>   //if the pedCount is greater than 20 (a value which will be sent via OSC)
> and b3base1 is equal to -1, i.e. the shred isn't currently running,
>   //add both shreds to the VM and assign their shred ID to the b3base1 and
> b3base2
>
>   if (pedCount > 20 && b3base1 == -1) {
>     Machine.add("b3base.ck") => b3base1;
>     Machine.add("b3base.ck") => b3base2;
>   }
>
>   else {
>
>     //if the pedCount is less than 20, remove both shreds from the VM and
> assign -1 to their value so that if the pedCount goes back above 20 they
>     //meet the conditional.
>
>     if (pedCount < 20 && b3base1 != -1) {
>       Machine.remove(b3base1);
>       Machine.remove(b3base2);
>       -1 => b3base1;
>       -1 => b3base2;
>     }
>   }
>
>   while( pedEvent.nextMsg() != 0) {
>     pedEvent.getInt() => pedCount;
>     2::second => now;
>   }
> }
>
> //endcode
>
> _______________________________________________
> chuck-users mailing list
> chuck-users at lists.cs.princeton.edu
> https://lists.cs.princeton.edu/mailman/listinfo/chuck-users
>


More information about the chuck-users mailing list