ssss wrote:
Hi sparks, I was wonderring if you could help me make a random block generator. What it would do is find a block on the Local block library, and display it. All credit would be given of course, but is it doable?
Well this will work: You just take the current block download code and set t1 to a random variable at the start:
download random block from the block library
|maker link t1 t2 t3 t4| t1_ self randomFrom: 1 to: 59. link_'http://dl.dropbox.com/u/6273449/', t1 asString, '.txt'. maker_self readLine: 1 FromUrl: link. t1_self readLine: 2 FromUrl: link. t2_self readLine: 3 FromUrl: link. t4_self readLine: 4 FromUrl: link. t4_self stringAsColor: t4. t3_self readLine: 5 FromUrl: link. createdBlocks at: t1 put: {t1. t1. '-'. ''. self class blockColorFor: 'custom'}.createdBlocks at: t1 put: {t1. t1. t2. t3. t4}.(t4 _ self ownerThatIsA: ScratchFrameMorph) ifNotNil: [t4 viewerPane categoryChanged: 'variables']. self showInformDialog: 'Sucess!' withText: 'The block has been added to your variables tab.', ' ', 'The "', t1, '" block', ' ', ' was shared by ', maker
note the "t1_ self randomFrom: 1 to: 59." on line two of the code! The only problem with this is that when more blocks are added to the library they will not be shown by this block unless you change the 59 to a new number. It might be possible to increment a counter until trying to read a block returns an error page but I'll leave you to research that!
Offline
sparks wrote:
ssss wrote:
Hi sparks, I was wonderring if you could help me make a random block generator. What it would do is find a block on the Local block library, and display it. All credit would be given of course, but is it doable?
Well this will work: You just take the current block download code and set t1 to a random variable at the start:
Code:
download random block from the block libraryCode:
|maker link t1 t2 t3 t4| t1_ self randomFrom: 1 to: 59. link_'http://dl.dropbox.com/u/6273449/', t1 asString, '.txt'. maker_self readLine: 1 FromUrl: link. t1_self readLine: 2 FromUrl: link. t2_self readLine: 3 FromUrl: link. t4_self readLine: 4 FromUrl: link. t4_self stringAsColor: t4. t3_self readLine: 5 FromUrl: link. createdBlocks at: t1 put: {t1. t1. '-'. ''. self class blockColorFor: 'custom'}.createdBlocks at: t1 put: {t1. t1. t2. t3. t4}.(t4 _ self ownerThatIsA: ScratchFrameMorph) ifNotNil: [t4 viewerPane categoryChanged: 'variables']. self showInformDialog: 'Sucess!' withText: 'The block has been added to your variables tab.', ' ', 'The "', t1, '" block', ' ', ' was shared by ', makernote the "t1_ self randomFrom: 1 to: 59." on line two of the code! The only problem with this is that when more blocks are added to the library they will not be shown by this block unless you change the 59 to a new number. It might be possible to increment a counter until trying to read a block returns an error page but I'll leave you to research that!
But it's not to download It's to show on the page [url]www.cyberkidscountry.com/s360.html[/img] where it should show code & the ('Block code thing' #-) as well as an image. So I need to use JS or html/css
Offline
sparks wrote:
... I realise I may have misunderstood. Did you want this to display a block from the library using php on a webpage?
Yes. That's exactly what I want to do! It should show, code ('This thing' #- #-) and an image!
Offline
Offline
Hmm.... I'm not certain how to read lines from other webpages into php variables... I've never needed to do that... But as Scimonster says above, you can use TheSucessor's block generator to display the image!
Offline
sparks wrote:
Hmm.... I'm not certain how to read lines from other webpages into php variables... I've never needed to do that... But as Scimonster says above, you can use TheSucessor's block generator to display the image!
But I wanted it to display a random block each time
I think I have to use something like a website with all the images, codes, and blockspecs sorted -_- Great... I'll probably have to do it all manually
Offline
Offline
scimonster wrote:
Do you understans what i want it to do?:
1. It gets (and displays) the Blockspecs
2. It gets (and displays) the code
3. It finds and displays the image renderred by the blockspec.
Offline
Get the source of the block lib page, and find the spec, code, and image.
Offline
scimonster wrote:
Get the source of the block lib page, and find the spec, code, and image.
How difficult would that be?
Funnily enough, the countdown for the 360 second rule is actually pretty accurate 0.o
Offline
I don't know PHP (yet), so: idk.
Offline
scimonster wrote:
I don't know PHP (yet), so: idk.
Alright, thanks for the help!
(For now, I'm working on a Scratch project!)
Offline
TheSuccessor wrote:
Pecola1 wrote:
OMG! TheSuccessor just gave me an idea!
I have a new block...
http://www.weebly.com/uploads/7/1/1/0/7 … 770768.gifBlockspec
('stop all scripts for %m' #- #stopAllScriptsFor: 'Stage')Code:
stopAllScriptsFor: t1 t1 stopAllMineYou first have to make the code that TheSuccessor made. e.g.
Code:
stopAllMine self scripts do: [:t1 | t1 stop]I don't have time to add it plus it might be better if we just save up blocks for a bigger update than just 1 block.
I think you might have to do this instead for the method:
Code:
stopAllScriptsFor: t1 (self coerceSpriteArg: t1) stopAllMineThe sprite name could be a string, so we have to use coerceSpriteArg: to make it a sprite.
Without my block, just do this:Code:
stopAllScriptsFor: t1 (self coerceSpriteArg: t1) scripts do: [:t1 | t1 stop]
I didn't think of that. XD Thanks.
Last edited by Pecola1 (2011-06-13 10:33:30)
Offline
Once i open the browser how do i add the code for the custom block?
Offline
NOW ADAPTED TO SCRATCH!!!!
Here is the user page block by sparks, changed from Panther to Scratch. This is my own code, so I can't guarantee it will work. I tried it and it SEEMED to work, but... you know.
blockspecs: ('open "my stuff" page for Scratch user %s' #- #doOpenForUser: scimonster)
ops: openForUser: t1
cursor wait showWhile ScratchPlugin primOpen URL: http://scratch.mit.edu/users/ t1
I hope this works!
Offline
SSBBM wrote:
pokemongardevoir wrote:
Once i open the browser how do i add the code for the custom block?
Scratch, BYOB, or Panther blocks?
Scratch, I think. (The open URL block)
Offline
pokemongardevoir wrote:
SSBBM wrote:
pokemongardevoir wrote:
Once i open the browser how do i add the code for the custom block?
Scratch, BYOB, or Panther blocks?
Scratch, I think. (The open URL block)
Okay, go to blockspecs. This is where you confirm the block exists, and you tell what it looks like. You also name the action it does.
for the URL block, I would do this (this is the blockspecs scimonster gave me):
('open URL: %s' #- #doOpen: )
the part in quotes is what the block says on it. the %s is a place for a string. #- means it is a stack block. #doOpen names the action open.
right click and choose accept, and go to instance. under other ops, replace the code of the broadcast with
open: t1
cursor wait showWhile ScratchPlugin primOpen URL: t1
or something like that. I think there is actually a bracket in there somewhere. anywho, that is how you code a block.
Oh, and awesome username (gardevoir is one of my faves -- treecko is my absolute favorite).
Offline
TuragaTreeko, you need quotes around strings for default values.
you wrote:
blockspecs: ('open "my stuff" page for Scratch user %s' #- #doOpenForUser: scimonster)
ops: openForUser: t1
cursor wait showWhile ScratchPlugin primOpen URL: http://scratch.mit.edu/users/ t1
This won't work. You need:
blockspecs: ('open "my stuff" page for Scratch user %s' #- #OpenUser: 'scimonster')
ops:
openUser: t1
Cursor wait showWhile: [ScratchPlugin primOpenURL: 'http://scratch.mit.edu/users/' , t1]
Offline
Haha, woops. I guess that wasn't as good as I hoped it would be. I'm not all that good at this. But I WILL keep trying! I'm determined.
did you notice I used you as the default value?
Offline
TuragaTreeko wrote:
Haha, woops. I guess that wasn't as good as I hoped it would be. I'm not all that good at this. But I WILL keep trying! I'm determined.
did you notice I used you as the default value?
Once you get better you wont make as many mistakes. But notice I said, "as many" I make a lot of mistakes still. XD I just recently compleatly forgot to put 'self' before commands for a whole script I was making. You may not make as many mistakes as I do.
Offline
OMG! The block library has 112 pages! Isn't that weird? Its so looooong.
Offline