Discuss Scratch

crazydoglady31
Scratcher
15 posts

How to type in passcode?

i am making an iphone project but in order to get in you have to type in the correct passcode–the thing is i want it to be where the numbers are displayed on the screen and you have to cick those to type in the passcode–but if you get it wrong it will deny you. All in all, i have no idea how to make a script!! Help?! or should just have them type it on their computer keys…
le_gameur_54
Scratcher
22 posts

How to type in passcode?

Can you give the like to your project please…
le_gameur_54
Scratcher
22 posts

How to type in passcode?

thx
AwesomeGameCreator
Scratcher
100+ posts

How to type in passcode?

Whenever your press a button, have it add that number to a stack or a variable. Then check if it is correct.
ie
define check_password
if <(entered_pw) = (correct_pw)> then
broadcast [allow_entry]


else
broadcast [incorrect_pw]
set [(entered_pw)] to []
end

Last edited by AwesomeGameCreator (April 12, 2017 21:18:08)

_nix
Scratcher
1000+ posts

How to type in passcode?

Well, we'd want a button for every key, right? So we'll need nine sprites. Since we want to form a “string” of characters (that is, a bunch of letters and/or numbers joined together in one variable), we'll make clicking each sprite add its respective character to our input variable string.

The usual method would be to make each of those sprites join a character onto the end of an input variable. That's pretty easy – just have this script inside of each button:

when this sprite clicked
set [Passcode Input v] to (join (Passcode Input) [1]) // Or whatever this button's number is!

Then you can have a “enter” button, which will check if you've got the right passcode input:

when this sprite clicked
if <(Passcode Input) = [1234]> then
broadcast [Logged in v] // Success!
else
set [Passcode Input v] to [] // Failed! Empty the passcode input so the user can try again.
end

Then you can make other sprites show or hide by using the “when I receive” block:

when I receive [Logged in v]
show // Or "hide". You can do other setup stuff here, too, of course!

Don't forget to reset the input variable to a blank value when you show the lock screen! You might also have a “reset” button that does something like this:

when this sprite clicked
set [Passcode Input v] to []

PS, you can use lists instead of the “join” block if you want. They work because you can actually use a list block to get all the text inside of a list joined together as one piece of text, if the list only contains one-character values. They're especially handy since it's easy to make a “delete” button:

when this sprite clicked
delete (last v) of [Passcode Input Numbers v]

Take a look at the tips pane if you're curious about using lists! It shouldn't be too hard to figure out how you can add characters to a list, and then check if the list makes the right string. It's pretty much the same as using text variables, just with slightly more control over the contents of the text.
crazydoglady31
Scratcher
15 posts

How to type in passcode?

thanks!
crazydoglady31
Scratcher
15 posts

How to type in passcode?

but how do I make the passcode entry bar…? (where the numbers go?)
le_gameur_54
Scratcher
22 posts

How to type in passcode?

AwesomeGameCreator
Scratcher
100+ posts

How to type in passcode?

crazydoglady31 wrote:

but how do I make the passcode entry bar…? (where the numbers go?)
Click the checkbox next to your password entry variable.
Now double click it, until it only shows the value (double click how it shows on the screen, below green flag)
Position it where you want it.
When your menu is shown, simply show the variable.
When it is not shown, hide it.
show variable [whatever_your_variable_is_called]
crazydoglady31
Scratcher
15 posts

How to type in passcode?

oh okay thanks!
crazydoglady31
Scratcher
15 posts

How to type in passcode?

one last thing…is it possible to make the passcode input hide until they are ready to type in the passcode (when the screen shows the lock)
AwesomeGameCreator
Scratcher
100+ posts

How to type in passcode?

Yes. When the green flag is press, hide it. When the menu is opened, show it. When the menu is closed, hide it.
crazydoglady31
Scratcher
15 posts

How to type in passcode?

oh i see it now.. hah duh thx

Powered by DjangoBB