This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2012-02-14 21:55:20

Mattheyy
New Scratcher
Registered: 2012-02-14
Posts: 3

Detecting the stop button pressed [HELPFUL]

Hey everyone! I'm an advanced Scratcher but this is my first post on the fourms. I hope to meet you guys and make some good friends though this  smile .

Firstly let me provide some background on my project,

I'm currently working on developing a working Scratch Virtual Operating system which will use python scripts to reference what I'm calling "Cloud Login" so it will feature and aspect of social interaction via the interface as there will be things like built in chat and an API for developing websites as well as shared login credentials meaning if you create a user on one machine it will work on an entirely different one.

As I'm developing this I came across a bit of a glitch in that if the user presses the stop button all loops and such are forced to terminate, however, click detectors were still active meaning that parts of the interface would glitch up most noticeably the toolbar of each Window would break free of the rest of the window and move around without the rest of the window following it.

So I came up with a clever back door to prevent this and pop up a funny blue screen message along the way.

So, here is how I detected the stop button as being pressed.

Firstly I created two variables, a "Clicked" variable, set to 0 on launch, a "Clicks" variable, again set to 0, and a "TheoreticalClicks" variable, again, set to 0 on launch.

Pre-existing in my code was a system where whenever any buttons are pressed it broadcasts a "Click" signal, this was used to trigger a sound playback from a central location to prevent duplication of the sound throughout each of the sprites. However, what I used it for in this example is as a reference. So, I made a "When I receive click" block CHANGE the "clicks" variable by 1 as well as SET the "Clicked" variable to 1. Then I have a constant loop, so, when the flag is pressed, run a forever loop. Inside that is a single if statement looking for the "Clicked" variable to be set to 1, when it sees this it instantly sets the clicked variable back to 0 and CHANGES "Theoretical Clicks" by 1. Now as you know when the stop button is pressed all loops cease to run. Meaning that if the stop button is pressed and somebody triggers the "Click" broadcast then only the "Clicks" variable is changed while the "TheoreticalClicks" variable remains at it's previous value. Finally, I have another when I receive click block that checks if the clicks variable is greater than the "TheoreticalClicks" variable. Meaning that if the loop  isn't running (When the stop button is pressed) and someone clicks something it makes the clicks variable greater than the Theoretical clicks and thus sets off this block. This particular block changes the background to a blue screen message and shuts off all the open Windows as well as disconnecting the ScratchSocket from transmitting network information.

Just something I thought I'd share with y'all. If you have any questions or feedback don't hesitate to ask, I'd be happy to assist!

Thanks,
Matt

Offline

 

#2 2012-02-14 22:00:37

MoreGamesNow
Scratcher
Registered: 2009-10-12
Posts: 1000+

Re: Detecting the stop button pressed [HELPFUL]

I'll be honest, I didn't read that as carefully as I should have, but isn't it easier to do this:

when gf clicked
forever
reset timer
end
When [Sprite1] Clicked
if <(timer) < [0.3]>
     do code
end
On the down side, this means that you won't be able to use the timer.  That could be a problem if you have a clock in your project.

Last edited by MoreGamesNow (2012-02-14 22:04:16)


http://images2.layoutsparks.com/1/218929/rubiks-cube-animated-rotating.gif
"Cogito ergo sum" --  I think, therefore I am

Offline

 

#3 2012-02-14 22:13:47

Mattheyy
New Scratcher
Registered: 2012-02-14
Posts: 3

Re: Detecting the stop button pressed [HELPFUL]

MoreGamesNow wrote:

I'll be honest, I didn't read that as carefully as I should have, but isn't it easier to do this:

when gf clicked
forever
reset timer
end
When [Sprite1] Clicked
if <(timer) < [0.3]>
     do code
end
On the down side, this means that you won't be able to use the timer.  That could be a problem if you have a clock in your project.

Yeah, as you said, the reason I avoided that method was because you can't use the timer which I need to initiate socket connections.

Thanks for the feedback though.  smile

Offline

 

#4 2012-02-14 22:17:23

Mattheyy
New Scratcher
Registered: 2012-02-14
Posts: 3

Re: Detecting the stop button pressed [HELPFUL]

Also guys, just thought I'd add, if you're interested in checking out the project or want to help out add me on Skype. My username is Mattheyy2. We're currently in need of some smart mathematical coders and python developers. Also if you'd like to contribute graphically (Sprites and such) let me know. I'd greatly appreciate it.

Offline

 

Board footer