| Author |
Message |
Stochastic

Joined: Feb 25, 2008 Posts: 16 Location: Vancouver
|
Posted: Tue Apr 01, 2008 7:10 pm Post subject:
30 Days of ChucK |
 |
|
Just thought I'd let people know,
I've signed up for the www.thirtydaysproject.com and as my project theme I'm teaching myself chuck by doing one 'song' a day.
You can view my codes and songs at http://www.sfu.ca/~edh2/april/
any feedback would be great, but keep in mind I'm new to all this so don't expect awesome programming skills
oh, and out of curiosity, is there a way to kill sporked shreds on command? |
|
|
Back to top
|
|
 |
Kassen
Janitor


Joined: Jul 06, 2004 Posts: 5961 Location: The Hague, NL
G2 patch files: 3
|
Posted: Tue Apr 01, 2008 7:42 pm Post subject:
|
 |
|
Great! Looking forward to seeing how this develops.
About killing shreds; assuming you want to kill them using code (and not manual commands) the most straightforward way would be
Machine.remove( foo );
where foo is a integer that's the id of the shred you want to kill. There are more ways but this will probably do for now. It's treated in the manual in the section on the "machine" namespace and of course there are sections on shreds.
Good luck! _________________ while(!machine.crash() ) <<<"all is well">>>; |
|
|
Back to top
|
|
 |
Inventor

Joined: Oct 13, 2007 Posts: 825 Location: Florida, USA
Audio files: 37
|
Posted: Tue Apr 01, 2008 7:51 pm Post subject:
Re: 30 Days of ChucK |
 |
|
| Stochastic wrote: | JI've signed up for the www.thirtydaysproject.com and as my project theme I'm teaching myself chuck by doing one 'song' a day.
oh, and out of curiosity, is there a way to kill sporked shreds on command? |
ACK! Thirty deadlines in thirty days! Well, that's one way to push yourself. It will be interesting to hear your songs, I remember writing some fun/good/OK stuff when I first started ChucKing so you can too.
The sporked shreads trick is one i have just discovered. You make a variable called int shred_id or similar and at the beginning of the shred's function definition you say "my.id () => shred_id;", then when you want to stop the shred you say "Machine.remove (shred_id);". It's a bit of a trick, but it works for me. I have a program that sporks or unsporks hundreds of shreds every "play" button push and it works fine there.
You can also reset shred_id to zero when you remove the shred and that way you can examine shred_id to see if the shred is launched, should you need that.
Good luck with your project and have fun learning ChucK! _________________ @(ºoº)@ ><}}}º> ~(^.^) <:3 )~ |
|
|
Back to top
|
|
 |
Stochastic

Joined: Feb 25, 2008 Posts: 16 Location: Vancouver
|
Posted: Tue Apr 01, 2008 7:54 pm Post subject:
|
 |
|
hmm I was trying to get the id of a sporked shred, by doing:
spork ~ foo() => int id;
or
spork ~ foo() => Shred @ int id; (as the manual kinda suggested)
or
spork ~ foo() => Shred @=> int id; (as the compiler then suggested)
but the compiler was having troubles resolving types. |
|
|
Back to top
|
|
 |
Inventor

Joined: Oct 13, 2007 Posts: 825 Location: Florida, USA
Audio files: 37
|
Posted: Tue Apr 01, 2008 8:08 pm Post subject:
|
 |
|
try this:
| Code: | // define the int
int id;
// define the function
function void shredder () {
// save the id
my.id () => id;
}
// spork the shred
spork ~ shredder ();
// wait
10::second => now;
// remove the shred
Machine.remove (id);
0 => id;
|
or something like that, didn't test it. _________________ @(ºoº)@ ><}}}º> ~(^.^) <:3 )~ |
|
|
Back to top
|
|
 |
Stochastic

Joined: Feb 25, 2008 Posts: 16 Location: Vancouver
|
Posted: Tue Apr 01, 2008 9:34 pm Post subject:
|
 |
|
The problem I have with that method is that I have various instances of the same function being sporked and my interest was in killing the older of the shreds.
Though I guess with a few adjustments it would be workable. |
|
|
Back to top
|
|
 |
Inventor

Joined: Oct 13, 2007 Posts: 825 Location: Florida, USA
Audio files: 37
|
Posted: Tue Apr 01, 2008 9:51 pm Post subject:
|
 |
|
Well, we are limited by the fact that the ChucK spork command does not report the shred id. The Machine.add (string path); function does however return the shred's id value. So I guess you could put your shred in a separate external file and then run it with Machine.add if you want. That's another option. _________________ @(ºoº)@ ><}}}º> ~(^.^) <:3 )~ |
|
|
Back to top
|
|
 |
Stochastic

Joined: Feb 25, 2008 Posts: 16 Location: Vancouver
|
Posted: Tue Apr 01, 2008 10:13 pm Post subject:
|
 |
|
So where they talk here: http://chuck.cs.princeton.edu/doc/language/spork.html#spork
about storing a reference to the shred in offspring, what does that mean?
offspring isn't declared anywhere so I don't know what type it is (not listed in reserved words either). |
|
|
Back to top
|
|
 |
Inventor

Joined: Oct 13, 2007 Posts: 825 Location: Florida, USA
Audio files: 37
|
Posted: Tue Apr 01, 2008 10:48 pm Post subject:
|
 |
|
I think you're referring to this:
| Code: | // spork another, store reference to new shred in offspring
spork ~ go() => Shred @ offspring; |
I dunno about that, I've never understood it. Maybe someone can explain it? I think it's sending an image of itself to a variable called offspring that is defined as type Shred or something, but this is way advanced ChucK for me, lol. _________________ @(ºoº)@ ><}}}º> ~(^.^) <:3 )~ |
|
|
Back to top
|
|
 |
Stochastic

Joined: Feb 25, 2008 Posts: 16 Location: Vancouver
|
Posted: Tue Apr 01, 2008 11:50 pm Post subject:
|
 |
|
| Oh, wait, I think I understand this. It stores a reference (see wikipedia) to the location of the Shred. This is much different than the ID number of the shred in the VM. I'm not sure of what this would be good for doing, but I'm no comp sci prof. |
|
|
Back to top
|
|
 |
Inventor

Joined: Oct 13, 2007 Posts: 825 Location: Florida, USA
Audio files: 37
|
Posted: Wed Apr 02, 2008 12:58 am Post subject:
|
 |
|
Yes, I think it is a a reference thingie. References dazzle and confuse me. I have yet to cozy up on them. _________________ @(ºoº)@ ><}}}º> ~(^.^) <:3 )~ |
|
|
Back to top
|
|
 |
Inventor

Joined: Oct 13, 2007 Posts: 825 Location: Florida, USA
Audio files: 37
|
Posted: Wed Apr 02, 2008 12:59 am Post subject:
|
 |
|
Yes, I think it is a a reference thingie. References dazzle and confuse me. I have yet to cozy up on them. _________________ @(ºoº)@ ><}}}º> ~(^.^) <:3 )~ |
|
|
Back to top
|
|
 |
Frostburn

Joined: Dec 12, 2007 Posts: 166 Location: Finland
Audio files: 5
|
Posted: Wed Apr 02, 2008 1:17 am Post subject:
|
 |
|
Is this what you're after (using references to get the id for removal):
| Code: | fun void sporky(){
<<<"Sporky","go!">>>;
second => now;
<<<"Sporky","leave...">>>;
}
spork~sporky();
2::second => now;
Shred shredReference;
spork~sporky() @=> shredReference;
0.5::second => now;
shredReference.id() => Machine.remove;
<<<"Sporky","killed.">>>;
3::second => now;
<<<"Have","a","nice",day>>>; |
I don't know why shredReference.exit(); doesn't work... Maybe a bug... _________________ In Serendipity We Trust |
|
|
Back to top
|
|
 |
Inventor

Joined: Oct 13, 2007 Posts: 825 Location: Florida, USA
Audio files: 37
|
Posted: Thu Apr 24, 2008 11:29 pm Post subject:
|
 |
|
Stochastic, how did your thirty days project go? I believe it has been more than thirty days since you started. Did you learn to ChucK or abandon the project? _________________ @(ºoº)@ ><}}}º> ~(^.^) <:3 )~ |
|
|
Back to top
|
|
 |
|