Wait... The only problem with custom blocks is that you cannot use them in a project you plan to share. It needs some javascript code to go with it, otherwise Java won't know how to handle the new block. Great tutorial, anyway.
Offline
randalpik wrote:
LS97 wrote:
The link block
Ok, finally some time to add the greatest block of all. the block links the user to a webpage, program or file as long as the path or URL is given. add in the blockspecs in the control section some kind of block code (choose whatever you want, you know how to do it). and add in the corresponding instance ops:Code:
Cursor wait showWhile: [ScratchPlugin primOpenURL: t1]So little code for such a great block... and remember to click accept!
For people who aren't sure how to put this in the block specs, here's a good way:
Code:
('go to website %s' #- #getLink: 'http://scratch.mit.edu/')The result will be a block that says "go to website [http://scratch.mit.edu/]" wherein scratch.mit.edu is what it says by default.
that code of urs almost crashed meh controlls!
Offline
If you make a mistake when coding a custom block and when try to use block it causes an error, all of your other custom blocks (but none of the normal ones) stop working and you have to restart Scratch. It's really annoying, so can anybody tell me why it does this? Also, why is it only the other custom blocks that jam up, not the normal ones?
Offline
TheSuccessor wrote:
If you make a mistake when coding a custom block and when try to use block it causes an error, all of your other custom blocks (but none of the normal ones) stop working and you have to restart Scratch. It's really annoying, so can anybody tell me why it does this? Also, why is it only the other custom blocks that jam up, not the normal ones?
Sometimes you have to click the stop-sign to dismiss the error.
Offline
^ I get that in CYOB but it stops all Panther blocks!
Offline
Name:
im clicked?
Type:
#b
Code:
clicked
|clicked other stage|
clicked_ 0.
stage _ self ownerThatIsA: ScratchStageMorph.
other_ self containsPoint: stage adjustedCursorPoint.
other = true
ifTrue:
[
clicked_ clicked + 1.
].
other_ self mousePressed.
other = true
ifTrue:
[
clicked_ clicked + 1.
].
clicked = 2
ifTrue:
[
^ true.
]
ifFalse: [
^ false.
].
Block Spec
Source:
('im clicked?' b clicked)
Normal:
('im clicked?' #b #clicked)
NOTE:
If used in CYOB remove the first line...
Offline
or just
| t1 |
(t1 _ self ownerThatIsA: ScratchStageMorph) ifNil: [^ false].
^ (self containsPoint: t1 adjustedCursorPoint)
& Sensor anyButtonPressed
Last edited by nXIII (2010-07-14 12:23:23)
Offline
LS97,
can you make these 2?
<talking?>
<say [] until <> > (i am far from pro at squeak!)
(edit = someone?)
Last edited by bbbeb (2010-07-18 22:09:37)
Offline
climber59 wrote:
For the [say () until <>] use
[say ()]
[wait until <>]
[blocks]<say[ blah ]>
<wait until>
<say[ ]>[/blocks]
That's what it should be, you forgot the "say []" to make the sprite stop talking.
Offline
Thanks for this tutorial. It has helped somewhat. So far, I'm able to read and understand little, aswell as easily create the blocks that you've guided us through. I have a desire for this certain block, since it will greatly improve the game I am working on. I would like to know how to add, "Replace [thing] of [List] with [thing]". I haven't surfed through all thirty-three pages of this thread, so if I missed anything important, like you're not taking suggestions anymore, then my bad.
Regards,
Ralphjos
Last edited by Ralphjos (2010-07-20 15:25:21)
Offline
I can give you some code to get
<place of %s in %L>
%s = textbox
%L = list
Offline
Oh well I was bored so I made it anyway:
Name:
replace item %s of %L with %s
Type:
-
Block Spec:
('replace item %s of %L with %s' #- #replace:list:with: 'hi' 'list' 'hello')
replace: t1 list: t2 with: t3 | t4 t5 t6 t7| t7_ 0. t4_ 0. t5_ self lineCountOfList: (t2). t6_ ''. t5 timesRepeat: [ t7_ t7 + 1. t4_ self getLine: (t7) ofList: (t2). t4 = t1 ifTrue: [ t6_ t7. ]. ]. t6 = '' ifTrue: [ t6_0. ] ifFalse:[ t6_ t6. self setLine: (t6) ofList: (t2) to: (t3). ].
EDIT:
You may use the block in a mod but give credit to JD or JD1.
Last edited by johnnydean1 (2010-07-20 16:19:49)
Offline
please call me JD or JD1
Offline
Oh and by the way if the list you want is like
hi
yay
and you put in
replace hello in list with happy
Then it will not replace anything.
Offline
johnnydean1 wrote:
Oh well I was bored so I made it anyway:
Name:
replace item %s of %L with %s
Type:
-
Block Spec:
('replace item %s of %L with %s' #- #replace:list:with: 'hi' 'list' 'hello')Code:
replace: t1 list: t2 with: t3 | t4 t5 t6 t7| t7_ 0. t4_ 0. t5_ self lineCountOfList: (t2). t6_ ''. t5 timesRepeat: [ t7_ t7 + 1. t4_ self getLine: (t7) ofList: (t2). t4 = t1 ifTrue: [ t6_ t7. ]. ]. t6 = '' ifTrue: [ t6_0. ] ifFalse:[ t6_ t6. self setLine: (t6) ofList: (t2) to: (t3). ].EDIT:
You may use the block in a mod but give credit to JD or JD1.
Why not just
self setLine: ((self listNamed: t2 ifNone: [^ self]) listContents indexOf: t1 ifAbsent: [^ self]) ofList: t2 to: t3
You don't need to give any credit for this one; and it's faster.
Last edited by nXIII (2010-07-21 20:22:48)
Offline
honmeg287 wrote:
i was unsuccesful with LS97's second post on the get time date block. please help!
Well, that code is completely legit, so I guess you'll just have to try again.
Offline
LS97 wrote:
The 'save stagearea to sprite' block
http://www.freeimagehosting.net/uploads/c8267d9caf.gif
I did this one on request of SeptimusHeap. it's maybe the easiest of the blocks. No coding needed, just add the block to the blockSpecs in ScratchSpriteMorph:Code:
('save stage area to sprite' #- #grabFromScreen)that's it! easy right?
PS. in case you didnt know, you have click accept.
Thanks for this too!
Offline