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-Objects → ScriptableScratchMorph. 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 specs → blockSpecs. 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)
Offline
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?
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
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-Objects → ScriptableScratchMorph → sensing ops. Replace the text in the bottom panel with the following:
keyPressed
^ Sensor keyboardPeek
Press alt + s. Select class → block specs → blockSpecs. 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)
Offline
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
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.
Offline
Hmmm... I can't get the (key pressed) block to work...
Offline
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)
Offline
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.
Offline
Are you able to add selection bullets and different buttons besides just "OK" ?
Offline
Offline
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?
Offline
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
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.
Offline
When I click ctrl+click on the third panel, it doesn't come up? Help?
Offline
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
How to make a password dialog: http://scratch.mit.edu/forums/viewtopic … 32#p522732
Offline