Making a code lock

andenn91's icon

Hi i want to create a code lock in max 5, and I want to use a counter to keep track of what number and in what order i pressed them, how can I do this?

Chris Muir's icon

What do you mean by "code lock?"

$Adam's icon

Hi,

if by 'code lock' you mean a mutex/semaphore like approach, I'm just building a generic [mutex] external that will be included in the next release of The sadam Library. But you'll need to wait a little bit for that (I'm hoping to launch the next release in a month, but as I'm doing it in my spare time, I can't make a promise). The basic idea is that you'll have many instances of the same object sharing the same name (like with coll, buffer etc.), and you'll be able to lock/unlock them all at the same time.

HTH,
Ádám

cap10subtext's icon

Sounds like OP is just looking for a passcode.

Max Patch
Copy patch and select New From Clipboard in Max.

andenn91: This isn't secure, but will perform the way you describe:

andenn91's icon

its a school project where im supposed to do a code lock that have a 4 digit code, and i have to press the code in correct order to unlock, and if i press the wrong order or a wrong digit it will reset, and I'm supposed to use a counter to keep track of what order i pressed :)

andenn91's icon
Max Patch
Copy patch and select New From Clipboard in Max.
Timo Rozendal's icon

[zl] is your friend, no, with [zl stream] and [zl compare] you don't need a counter

andenn91's icon

some example how to use it?

Timo Rozendal's icon

no, do your homework :-) (aka read the helpfile)

andenn91's icon

i´ve tried for 24 hours now, i have to hand it in soon :/

laonikoss's icon

What elements do you need for the password thing?

1) Something to recognise what keys you have pressed and in which order
2) Something that compares what keys you pressed to what keys you are supposed to have pressed.

You can use a combination of [counter], [pack], [coll] and [if], which is what I assume you have been tasked to do - but there are much simpler (and more flexible) ways using objects which you might not have covered in your class yet, involving [textedit] or [zl stream] and [zl compare].

Put your mind down to use - it's only an exercise, if you couldn't do it on time, tell the teacher and he will help you, it's not a crime!

cap10subtext's icon

If you were up front about it being a school assignment, we could have helped point you in the right direction earlier and helped described the correct approach. I can't speak for everyone but if you think I would just hand over the code that finishes your homework for you, you are sadly mistaken. Better to ask the teacher BEFORE the deadline if he/she can be of more help.

The post above this one has a lot of helpful techniques. Basically in order to do this, you are asked to keep track of what's been pushed. Using an object like table or pack and route will let you take the number from the counter (the order or index) and pack it to a list with the number of the key you pushed. Route could then help you separate out the numbers (according to index) and then test them.

The trigger object is also your friend, it will help you with the "reset if incorrect" part of the problem.