Discuss Scratch

smellyellie1234
Scratcher
51 posts

HELP PLEASE

I'm making a ATM Simulator and I've made it so it has a pin code you need to enter. I have a keypad on the ATM with numbers 0-9 that are all separate scripts. my scripts go something like:

(NOTE: Pin 1 Pin 2 etc. and #Pin 1 #Pin 2 are variables, Pin 1 being the first number of the pin code and so on and #Pin 1 being the number you have entered into the keypad that you think is the first number. Also keypad 1 means the number one on the keypad and so on.)

when green flag clicked
set Pin 1 to 1
Set pin 2 to 2
set pin 3 to 3
set pin 4 to 4

when I receive [Enter Pin 1}
forever
if <<touching (keypad 1)> and <mouse down>>
set #pin 1 to 1
broadcast Enter Pin 2

(this script is then repeated for all the other numbers on the keypad and for all the other numbers in the pin code except I change what your setting #pin to and what it broadcasts)

When I receive [Pin Entry Complete}
forever
if
<Pin 1 = #Pin 1> and <Pin 2 = #Pin 2> and <Pin 3 = #Pin 3> and <Pin 4 = #Pin 4>
broadcast Pin number correct
else
broadcast Pin incorrect

when I receive Pin correct
switch to costume Costume 2

However after trying it out many times the costume doesn't change to costume 2 when I enter the correct Pin. If you need to I can share the project and add a link but I prefer editing my projects on 1.4 so if possible I'd prefer not to

drmcw
Scratcher
1000+ posts

HELP PLEASE

Doesn't seem a particularly good way to do it tbh but anyway the problem may be the forever loop you have in when I receive {Pin Entry Complete] I wouldn't expect that to need a forever loop.

10 !
ScratchVaders or Galaga?
Maybe Eliza can help you decide?
smellyellie1234
Scratcher
51 posts

HELP PLEASE

drmcw wrote:

Doesn't seem a particularly good way to do it tbh but anyway the problem may be the forever loop you have in when I receive {Pin Entry Complete] I wouldn't expect that to need a forever loop.


Thank you so much However, I made it so the #Pin and the Pin show so I can see where the problem is and when I click the keys absolutely nothing happens the #pin number doesn't change. Also, how would you recommend doing it if there's an easier way?

Last edited by smellyellie1234 (Sept. 1, 2013 10:28:42)

scubajerry
Scratcher
1000+ posts

HELP PLEASE

smellyellie1234 wrote:

drmcw wrote:

Doesn't seem a particularly good way to do it tbh but anyway the problem may be the forever loop you have in when I receive {Pin Entry Complete] I wouldn't expect that to need a forever loop.


Thank you so much However, I made it so the #Pin and the Pin show so I can see where the problem is and when I click the keys absolutely nothing happens the #pin number doesn't change. Also, how would you recommend doing it if there's an easier way?

You should share your project if you want help.
drmcw
Scratcher
1000+ posts

HELP PLEASE

smellyellie1234 wrote:

drmcw wrote:

Doesn't seem a particularly good way to do it tbh but anyway the problem may be the forever loop you have in when I receive {Pin Entry Complete] I wouldn't expect that to need a forever loop.


Thank you so much However, I made it so the #Pin and the Pin show so I can see where the problem is and when I click the keys absolutely nothing happens the #pin number doesn't change. Also, how would you recommend doing it if there's an easier way?

Ok the way I would do it was have a variable called ATMEntry say and set this to blank when green flag clicked then whenever a button is pressed let's say button 1 then
when [button1 v] sprite clicked
set [ATMEntry v] to (join (ATMEntry) [1])

for button 2 you'd join 2 etc. If clear button pressed then just set ATMEntry to blank but when enter is pressed;
when [Enter v] sprite clicked
if <(ATMEntry) = [1234]> then
broadcast [PIN OK v]
else
set [ATMEntry v] to []
end

where 1234 is the correct PIN number

Last edited by drmcw (Sept. 1, 2013 19:34:13)


10 !
ScratchVaders or Galaga?
Maybe Eliza can help you decide?
smellyellie1234
Scratcher
51 posts

HELP PLEASE

drmcw wrote:

smellyellie1234 wrote:

drmcw wrote:

Doesn't seem a particularly good way to do it tbh but anyway the problem may be the forever loop you have in when I receive {Pin Entry Complete] I wouldn't expect that to need a forever loop.


Thank you so much However, I made it so the #Pin and the Pin show so I can see where the problem is and when I click the keys absolutely nothing happens the #pin number doesn't change. Also, how would you recommend doing it if there's an easier way?

Ok the way I would do it was have a variable called ATMEntry say and set this to blank when green flag clicked then whenever a button is pressed let's say button 1 then
when [button1 v] sprite clicked
set [ATMEntry v] to (join (ATMEntry) [1])

for button 2 you'd join 2 etc. If clear button pressed then just set ATMEntry to blank but when enter is pressed;
when [Enter v] sprite clicked
if <(ATMEntry) = [1234]> then
broadcast [PIN OK v]
else
set [ATMEntry v] to []
end

where 1234 is the correct PIN number

Thank you so much!

Powered by DjangoBB