bang when patch is unlocked

frnce78975's icon

Anyone know how to receive a bang when the patch it unlocked? I can't seem to find the object/workaround.

Thanks.

Ben Bracken's icon

This is something that you can get at via javascript. this.patcher.locked will return a 0 (unlocked) or 1 (locked).

-Ben

frnce78975's icon

thank you both. Ben, do you think you can post an example for those of us who aren't Javascript programmers?

ShelLuser's icon

I don't think the OP wants to check the state of the patch, IMO he wants to trigger a bang the very moment the patch gets unlocked.

V.J.'s icon

Post the code below in a js object, then send the message poll to the object. It will check the state of the patch every 100 milliseconds. If you want to find out the state of the patch just once, send the message lockstate.

var polling = new Task(lockstate);

function lockstate()
{
outlet(0, this.patcher.locked);
}

function poll()
{
polling.interval = 100;
polling.repeat();
}