Scratch Forums down for maintenance this morning just about broke my heart.
Offline
Agreed.
Offline
bharvey wrote:
Did something change recently that's making me have to log in all the time? Used to be I could stay logged in forever.
Yeah, I'm finding that. I'm sure the forums usually let you stay logged in for longer than the main Scratch site, too... or is that just me?
Offline
bharvey wrote:
Did something change recently that's making me have to log in all the time? Used to be I could stay logged in forever.
Same. I have to log in whenever i use scratch from a computer, but i am auto logged in whenever i use my phone. [/offtopic]
Anyways: Snap suggestion: Thread variables! They would be variables that every thread defined in the lexical scope of the variable has a unique copy to. Would be useful for my nondeterminism project, as each thread can have it's own fail continuation and another thread with another fail continuation could not interfere. Would also be useful for servers once we get some form of networking (such as mesh) in snap. If i think of any more examples, i will say.
Offline
Jens wrote:
joefarebrother wrote:
Snap suggestion: Thread variables
interesting suggestion. How aren't Script Variables what you need?
Because if a custom block referenced a variable that every thread should have a unique copy to, it won't know which binding to use as to not mess up the program. It's basically a subset of dynamic scope.
Offline
bharvey wrote:
Did something change recently that's making me have to log in all the time? Used to be I could stay logged in forever.
Random logout bug. It used to happen to me every five minutes when I used FireFox. Then I migrated to Safari and it fixed itself.
Offline
Hey guys! Remember way, way back when I promised a script to assist in embedding Snap! in web pages without using iframes? I finally finished a testing version!
To create an instance of snapembed, all you need is snapembed.js and the snap directory which contains a minified version of Snap! as well as a couple of images. Reference them in the header:
<head> <script type="text/javascript" src="snapembed.js"></script> <script type="text/javascript" src="snap/snap.js"></script> </head>
Then include the snapembed code at the end of the body tag:
<body> <!--Some Code--> <script type="text/javascript"> var snapembed = new snapembed(false); snapembed.create('example_contain',{width:800,height:600}); snapembed.create('example_contain2',{width:1024,height:768}); </script>
Starting snapembed is simple. Make a variable by any name that you will use to reference the script (var example = new snapembed(true)). The paramater inside snapembed is required. It specifies whether each instance of Snap! can be run simultaneously. False means they will be run one at a time, as in the demo.
To create a new instance of Snap! use the line of code:
snapembed.create(id of container,options);
This takes two paramaters: the id of a div that will contain the instance of Snap! and the options. Currently there are two options, width and height, specified like so: {width: 100, height:100}.
To edit one of these options, use:
snapembed.edit(id of container, option, value);
Editing of width and height is under construction, as you can see from the demo.
Also, don't use unit when specifying lengths.
MORE FEATURES COMING SOON!
Last edited by shadow_7283 (2012-09-03 22:17:26)
Offline
Jens, (or anyone else familiar with Snap! / morphic), my snapembed script can update the width of the world morph, but I'm unsure how to update Snap!'s width. Can anyone help me out?
Offline
shadow_7283 wrote:
Jens, (or anyone else familiar with Snap! / morphic), my snapembed script can update the width of the world morph, but I'm unsure how to update Snap!'s width. Can anyone help me out?
The whole Snap interface is an instance of IDE_Morph. Try this:
world.children.filter(function(m){ return m instanceof IDE_Morph; })[0].setExtent(new Point(width,height))
Careful, I am having trouble getting it to shrink past a certain size.
Offline
shadow_7283 wrote:
a script to assist in embedding Snap! in web pages
Cool!
contains a minified version of Snap!
Does this mean that you have to have your own local Snap!, rather than running the latest one in the embedded window?
Also, did you have to modify Snap! to make it work?
My top priority missing feature (unless I'm misreading your post) is the ability to specify a project with #open or (when Jens finishes it) #run. I think people are less likely to want to embed raw Snap! on their pages than to embed a particular project.
Offline
Yeah, opening is coming soon, I just wanted to commit myself to the project by posting an early version here. Snap! was not modified. Although it's a local copy, you and Jens could easily host a remote copy for users to reference (similar to google and jQuery).
Thanks for the tip fullmoon. By the way, I'm sure my script semantics are awful, so if you have any tips for improvement let me know. I considered using jQuery, but decided it would probably be unnecessary.
Offline
Great idea, shadow! I've been playing with a Snap runtime myself recently - just a single condensed JS file within a single function which encapsulates its own namespace. That way we can create both stand-alone executables and also embed any project into any web page simply by linking to the hosted runtime. But your way is also very interesting!
Offline
Is it possible to embed XML into a HTML <div> and access it via the innerHTML function?
If so, the following code should work, although I haven't tested it yet.
To embed a project, use
<div class="snap">
T<xml or the project, or the url it is saved at>
</div>
Put F instead of T if you want the user to be able to enter edit mode, and use the green flag and pause button and stop sign
The code:
var projects = document.getElementByTagName("div").filter(function(div){return div.className == "snap"}), worlds = []; projects.forEach(function (project){ var contents = project.innerHTML, appMode = contents.charAt(0) == "T", //T or F savedProject = contents.slice(1), // URL or embedded XML canvas, world, ide, oldHash; project.innerHTML = ""; //clear the div canvas = project.appendChild(document.createElement("canvas")); canvas.width = project.clientWidth; canvas.height = project.clientHeight; world = new WorldMorph(canvas); worlds.push(world); ide = new IDE_Morph(); ide.setExtent( new Point(project.clientWidth, project.clientHeight); //open the project oldHash = location.hash; location.hash = "#open:" + savedProject; ide.openIn(world); location.hash = oldHash; //Put in app mode if needed if (appMode){ ide.isAppMode = true; ide.controlBar.hide(); //hide the edit mode button,the green flag,pause button and the stop button } }); setInterval(loop, 1); function loop(){ worlds.forEach(function (world){ world.doOneCycle(); }); }
Offline
joefarebrother wrote:
Put F instead of T if you want the user to be able to enter edit mode, and use the green flag and pause button and stop sign
I should think a popular choice would be yes to green flag etc but no to edit -- or alternatively a way to superimpose a half-transparent play button over the whole project, a la youtube embedded videos.
Offline
joefarebrother wrote:
Is it possible to embed XML into a HTML <div> and access it via the innerHTML function?
Yes although that's definitely considered bad practice by most web developers. Most browsers will consider any XML inside a div to be HTML, which means that they may mess with the attributes and structure of the document — and parsing an XML tree the size of those that Snap produces is a lot of pointless work for the browser that will slow down rendering. Far better to just load it with XMLHttpRequest! If you really need to put a Snap file inside a webpage I would use a <script type='text/snap'> element. The browser (probably) won't consider it Javascript and you could tell Snap to grab the innerHTML of that and parse it.
Offline
bharvey wrote:
joefarebrother wrote:
Put F instead of T if you want the user to be able to enter edit mode, and use the green flag and pause button and stop sign
I should think a popular choice would be yes to green flag etc but no to edit -- or alternatively a way to superimpose a half-transparent play button over the whole project, a la youtube embedded videos.
That sounds good. And make the flag bar appear on hover, like the youtube play/pause/ff/rewind bar.
Offline
'K, improved the code:
var projects = document.getElementsByTagName("script").filter( function (script){ return script.getAttribute("type"); }), worlds=[] projects.forEach(function (project){ var canvas = document.createElement("canvas"), world = new WorldMorph(), ide = new IDE_Morph(), control = ide.controlBar, appModeButton = control.appModeButton, pauseButton = control.pauseButton flag = control.children.filter( function (morph){ return morph instanceof PushButtonMorph && morph.action = 'runScripts'; })[0], stop = control.children.filter( function (morph){ return morph instanceof PushButtonMorph && morph.action = 'stopAllScripts'; })[0], contents = project.innerHTML, start = contents.indexOf("!"), end = start ? contents.indexOf("!", start + 1) : 0, options = start ? contents.substring(start + 1, end).split(",") : [], projCode = start ? contents.substring(end + 1) : contents, hideEdit = options.contains("noEdit"), hideFlag = options.contains("noFlag"), hideStop = options.contains("noStop"), hidePause = options.contains("noPause"), controlBarHover = detect( options, function (str){ return str.substring(0, 7) = "hover:" } ).substring(7), oldHash = location.hash; project.parentNode.replaceNode(canvas, project); //open project location.hash = "#open:" + projCode; ide.openIn(world); location.hash = oldHash; ide.isAppMode = true; //hide the buttons the user wants to hide if (hideEdit){ appModeButton.hide(); } if (hideFlag){ flag.hide(); } if (hideStop){ stop.hide(); } if (hidePause){ pause.hide(); } if (controlBarHover){ var shownYPos = controlBar.topLeft().y, hiddenYPos; controlBar.setPosition(new Point( controlBar.topLeft().x, (shownYPos + 2) - controlBar.height() )); hiddenYPos = controlBar.topLeft().y; controlBar.fps = 12; controlBar.mouseEnter = function (){ controlBar.step = function(){ controlBar.setPosition(new Point( controlBar.topLeft().x, controlBar.topLeft().y + controlBarHover )); if (controlBar.topLeft().y > shownYPos){ controlBar.step = nop; } }; }; controlBar.mouseLeave = function (){ controlBar.step = function(){ controlBar.setPosition(new Point( controlBar.topLeft().x, controlBar.topLeft().y - controlBarHover )); if (controlBar.topLeft().y < hiddenYPos){ controlBar.step = nop; } }; }; } ide.runScripts worlds.push(world); }); setInterval(loop, 1); function loop(){ worlds.forEach(function (world){ world.doOneCycle(); } }
Syntax:
<script type = "text/snap">
!options!embedded XML or project URL
</script>
For the options, write a comma-separated list (without spaces) with 1 or more of the following options: (if there are no options, you can omit the options bit altogether: don't put in the !s)
noEdit - hides the edit button
noFlag - hides the green flag
noStop - hides the stop sign
noPause - hides the pause button
hover:### - makes the control bar slide on and off screen mouse hover, at a speed specified by ###
Don't put any whitespace between the closing ! of the options bit and the start of the URL/XML.
Untested.
Last edited by joefarebrother (2012-09-08 04:27:46)
Offline
Awesome! You've definitely made a much more sophisticated (and semantically correct) product!
Jens, I don't know if you have anything official planned as far as embedding is concerned, but we could start a Google Code project for Snap! Embed if you all think it's a good idea.
Last edited by shadow_7283 (2012-09-07 18:21:33)
Offline
I still don't understand why
doesn't work
(it doesn't save properly OR run properly)
Last edited by joefarebrother (2012-09-08 08:08:36)
Offline
joefarebrother wrote:
I still don't understand why
http://i50.tinypic.com/14jbx9l.jpg
doesn't work
(it doesn't save properly OR run properly)
Jens (who's on vacation right now) said something about a bug regarding multiple unevaluated inputs, I think. I'm not sure what the status of that is. I'm sure he'll reply when he's back.
Offline
Hey bharvey, I know you once wrote an article on pattern-matching like REgEx(p?) It went way over my head six months ago, but I think I can grok it now. Can you dig it out for me, please? Thanks!
Offline