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

#1 2010-02-28 14:48:53

nXIII
Community Moderator
Registered: 2009-04-21
Posts: 1000+

Scratch Dialog Block

Here is my mini-tutorial on how to make a Scratch block that makes a dialog come up to inform the user. It takes two arguments, the title of the dialog and the text (both which you can put reporter blocks and variables into). To start, turn fill screen off by shift-clicking the loop in the R in the Scratch logo and selecting turn fill screen off.

Note: shift-clicking means clicking something while holding the shift key.

Click in the whitespace and select open..., then browser. Click Scratch-ObjectsScriptableScratchMorph. Next, hold ctrl while clicking anywhere in the third panel of the window. Select new category...new..., then type in dialog ops and click accept(s). Mouse over the bottom panel in the window and paste the following (using alt + v):

showInformDialog: t1 withText: t2
    DialogBoxMorph inform: t2 title: t1

Press alt + s to save your changes. Next, select class from the three buttons in the second panel (instance, ?, and class). Select block specsblockSpecs. Scroll down, and right before 'motor' (it doesn't really matter where you put it) add the following (copy, then paste with alt + v):

'sensing' ('show dialog titled %s with contents %s' #- #showInformDialog:withText: 'information' 'some information')

It doesn't matter what the last two items in quotes are, set them to what you want the default arguments in the Scratch block to be, or delete them to have blank default arguments. Press alt + s to save the changes, and close the browser. Go to sensing, and the new block should be at the bottom. Click it once or twice to test it with different arguments, then shift-click the R in the Scratch logo again and select save image for end-user, then yes. Open Scratch again (it should close) and your new block should still be there. Use it well!

Very important note: Projects with this block will be able to save fine on your computer, but will not work if posted online, and when downloaded by other users will appear as a red obsolete block. I advise you not to post projects with this or other user-created blocks

Last edited by nXIII (2010-10-12 15:01:52)


nXIII

Offline

 

#2 2010-02-28 15:09:55

The-Whiz
Scratcher
Registered: 2007-07-09
Posts: 1000+

Re: Scratch Dialog Block

Nice.

Offline

 

#3 2010-02-28 15:15:52

Lucario621
Community Moderator
Registered: 2007-10-03
Posts: 1000+

Re: Scratch Dialog Block

Cool!


http://i.imgur.com/WBkM2QQ.png

Offline

 

#4 2010-02-28 15:42:27

shadow_7283
Scratcher
Registered: 2007-11-07
Posts: 1000+

Re: Scratch Dialog Block

AWESOME! I love the hack. I'm going to see how good it really is...

EDIT: It works really well on Scratch but... It is pretty much pointless to use it in projects you are going to share because it doesn't work online and when downloaded the block appears as "obsolete" and doesn't function (like nXIII said).

Do you know of anyway to un-obsolete it?  big_smile

EDIT: I have a challenge for you... can you make a...

(key pressed) block?!?!?! So it would read "a" if the "a" key was pressed. It would shorten so much irritating code...

Last edited by shadow_7283 (2010-02-28 16:11:14)

Offline

 

#5 2010-02-28 16:53:51

nXIII
Community Moderator
Registered: 2009-04-21
Posts: 1000+

Re: Scratch Dialog Block

shadow_7283 wrote:

EDIT: I have a challenge for you... can you make a...

(key pressed) block?!?!?! So it would read "a" if the "a" key was pressed. It would shorten so much irritating code...

OK I will try now... *Opens Scratch*

...

...

Sorry, for some reason this worked when I clicked the block, but not when I put it in a script...strange. I am going to try to fix it now.

Turn fill screen off as always. Open a browser, and navigate to Scratch-ObjectsScriptableScratchMorphsensing ops. Replace the text in the bottom panel with the following:

keyPressed
    ^ Sensor keyboardPeek

Press alt + s. Select classblock specsblockSpecs. Add (after the dialog block) the following:

('key pressed' #r #keyPressed)

Press alt + s. Test it if you want and save the image for end-user.

Note: Interestingly enough, this will detect if the shift key is pressed while pressing another key, and return a different value if so. Keys like esc will not return esc, they will return a character that cannot be displayed (a little box thing). I think if you can copy that character an paste it into a comparison , it might still work. It will return nil if no key is pressed.

Last edited by nXIII (2010-02-28 16:59:42)


nXIII

Offline

 

#6 2010-02-28 16:57:22

fanofcena
Scratcher
Registered: 2008-07-03
Posts: 1000+

Re: Scratch Dialog Block

good job


http://i53.tinypic.com/2vxr2c0.png Click whats above u might make a cute planet happy ^_^

Offline

 

#7 2010-02-28 17:52:37

songhead95
Scratcher
Registered: 2008-03-19
Posts: 100+

Re: Scratch Dialog Block

I did that, but in presentation when you drag it around, it leaves a trail. So I made a new version of ScratchDialogMorph (or something) that is impossible to drag.

That, plus many other features (Such as file I/O) are in my project, "Scratch Softdev Sdk"

Offline

 

#8 2010-02-28 18:32:06

nXIII
Community Moderator
Registered: 2009-04-21
Posts: 1000+

Re: Scratch Dialog Block

songhead95 wrote:

I did that, but in presentation when you drag it around, it leaves a trail. So I made a new version of ScratchDialogMorph (or something) that is impossible to drag.

That, plus many other features (Such as file I/O) are in my project, "Scratch Softdev Sdk"

Just make a 'repaint' block.


nXIII

Offline

 

#9 2010-02-28 18:42:09

shadow_7283
Scratcher
Registered: 2007-11-07
Posts: 1000+

Re: Scratch Dialog Block

Hmmm... I can't get the (key pressed) block to work...

Offline

 

#10 2010-02-28 22:01:54

billyedward
Scratcher
Registered: 2008-01-03
Posts: 500+

Re: Scratch Dialog Block

The problem with this is that it also messes up in full screen mode.
A less elegant, but more versatile method is to simply add ('alert %s' #- #inform:) to the block specs.

You can also change this to ('confirm %s' #b #confirm:) to ask the user to say yes or no and report the result in a boolean block.

Neither of these, also, require a new function to be declared; just change the block specs!

Last edited by billyedward (2010-02-28 22:02:57)


"I'd love to change the world, but they haven't released the source code yet."
Check out the latest version of Streak --> http://billy.scienceontheweb.net/Streak

Offline

 

#11 2010-02-28 22:14:36

Dazachi
Retired Community Moderator
Registered: 2009-09-12
Posts: 1000+

Re: Scratch Dialog Block

This looks really complicated. When I am not half-asleep like right now, I might attempt to do this.


Dazachi, Retired Community Moderator
May also know me as OJACheung.

Offline

 

#12 2010-03-01 18:09:21

nXIII
Community Moderator
Registered: 2009-04-21
Posts: 1000+

Re: Scratch Dialog Block

billyedward wrote:

The problem with this is that it also messes up in full screen mode.
A less elegant, but more versatile method is to simply add ('alert %s' #- #inform:) to the block specs.

You can also change this to ('confirm %s' #b #confirm:) to ask the user to say yes or no and report the result in a boolean block.

Neither of these, also, require a new function to be declared; just change the block specs!

LOL! I didn't know they were already functions...
For the fullscreen thing, I think I can just add a 'force repaint' block to use in combination with it. A bit strange, but oh well.


nXIII

Offline

 

#13 2010-03-01 18:54:50

Greenboi
Scratcher
Registered: 2010-01-30
Posts: 1000+

Re: Scratch Dialog Block

Cool! Nice work nxII!

Offline

 

#14 2010-04-19 20:05:15

Jakey22
Scratcher
Registered: 2008-12-28
Posts: 72

Re: Scratch Dialog Block

Are you able to add selection bullets and different buttons besides just "OK" ?


http://www.imagebookers.com/gallery/d/2561-1/ubuntu-wallpaper.png http://bullylug.org/linux-penguin.jpg
My website       PENGUINS!!!!!!!!!!!!!!!!!!!!! randomness.

Offline

 

#15 2010-04-20 20:12:58

Jakey22
Scratcher
Registered: 2008-12-28
Posts: 72

Re: Scratch Dialog Block

Bump everyone!!


http://www.imagebookers.com/gallery/d/2561-1/ubuntu-wallpaper.png http://bullylug.org/linux-penguin.jpg
My website       PENGUINS!!!!!!!!!!!!!!!!!!!!! randomness.

Offline

 

#16 2010-05-01 06:05:41

TheSuccessor
Scratcher
Registered: 2010-04-23
Posts: 1000+

Re: Scratch Dialog Block

With the dialog box you get annoying layering problems with variables. Half the variable is on top and half underneath. Can you sort this out?


/* No comment */

Offline

 

#17 2010-05-08 08:02:04

LS97
Scratcher
Registered: 2009-06-14
Posts: 1000+

Re: Scratch Dialog Block

Jakey22 wrote:

Are you able to add selection bullets and different buttons besides just "OK" ?

you can do that with the function customMenu. but that's a bit more complicated...

Offline

 

#18 2010-05-08 11:28:19

Joeman592
Scratcher
Registered: 2010-01-23
Posts: 100+

Re: Scratch Dialog Block

How can you make another catagory that works?


http://i.imgur.com/HcAj1.png
http://i.imgur.com/gss7S.gifhttp://i.imgur.com/kbcKt.gifhttp://i.imgur.com/0LteM.gif

Offline

 

#19 2010-05-08 13:20:14

TheGameMaster1231
Scratcher
Registered: 2009-07-24
Posts: 1000+

Re: Scratch Dialog Block

Jakey22 wrote:

Are you able to add selection bullets and different buttons besides just "OK" ?

Ya! Except I'm At My Grandmother's House, And She Doesn't Have Scratch Downloaded. So I Can't Check How Right Now.  sad

Offline

 

#20 2010-05-10 11:16:00

tom5X5
Scratcher
Registered: 2009-05-16
Posts: 26

Re: Scratch Dialog Block

this is really cool! thanks a ton!

Offline

 

#21 2010-09-23 14:36:41

ProgrammingFreak
Scratcher
Registered: 2010-09-04
Posts: 1000+

Re: Scratch Dialog Block

When I click ctrl+click on the third panel, it doesn't come up? Help?

Offline

 

#22 2010-09-23 14:41:44

Jwosty
Scratcher
Registered: 2009-12-19
Posts: 500+

Re: Scratch Dialog Block

ProgrammingFreak wrote:

When I click ctrl+click on the third panel, it doesn't come up? Help?

What third panel? Are you talking about the R that you shift-click?


http://i39.tinypic.com/18ert5.png Google it.  smile

Offline

 

#23 2010-09-23 15:22:01

ProgrammingFreak
Scratcher
Registered: 2010-09-04
Posts: 1000+

Re: Scratch Dialog Block

nxii wrote:

hold ctrl while clicking anywhere in the third panel of the window. Select new category... → new..., then type in dialog ops and click accept(s).

It doesn't work for me!

Offline

 

#24 2010-09-24 02:53:14

Daffy22
Scratcher
Registered: 2008-12-15
Posts: 500+

Re: Scratch Dialog Block

nXIII wrote:

Silly little mods

What are you saying... all mods (including panther) are silly and pointless!!  mad
I'd like it if you changed that line!  smile


http://img201.imageshack.us/img201/1784/logosmalle.png
"Spectacular - 5 Star" -  CNET.com Editor.

Offline

 

#25 2010-09-24 14:26:29

TheSuccessor
Scratcher
Registered: 2010-04-23
Posts: 1000+

Re: Scratch Dialog Block


/* No comment */

Offline

 

Board footer