Discuss Scratch

bharvey
Scratcher
1000+ posts

Snap! user discussion

Jonathan50 wrote:

You can make a block that iterates over the list and adds each item to a new list (if that's really what you want).
… recursively, so the elements of elements, etc., are also made separate.

But of course the best solution is functional programming, so you never mutate a list, and then you don't have to worry about it!

hjcpps
New to Scratch
40 posts

Snap! user discussion

Beyond lists, I can have a reference to a command script. This script can have a state, using the block variables experimental feature, or the “Local State with Script Variables” method described in section VIII.A of the manual. There isn't a way to copy this object (script reference plus local variable state) without writing my own copy constructor?
nigeldodd
Scratcher
14 posts

Snap! user discussion

Sorry if this has been answered already. I need to get (flat list) data out of a Snap program. I appreciate Javascript deliberate limitations of browser based programs so understand why it is difficult, but I can't even seem to get a block of numbers to copy and paste into something else.

What is the workaround for this, please? Do I need to create a web page into which I can POST the data - this seems so much trouble!

N
hjcpps
New to Scratch
40 posts

Snap! user discussion

bharvey wrote:

If you have an atomicity problem, please send a project that fails.
Despite being acutely aware of race conditions, I fell into the trap.

http://snap.berkeley.edu/run#present:Username=hjcpps&ProjectName=discuss_005&editMode

I do see what likely happens. Verification and a solution will have to wait until tomorrow.
cycomachead
Scratcher
100+ posts

Snap! user discussion

nigeldodd wrote:

Sorry if this has been answered already. I need to get (flat list) data out of a Snap program. I appreciate Javascript deliberate limitations of browser based programs so understand why it is difficult, but I can't even seem to get a block of numbers to copy and paste into something else.

What is the workaround for this, please? Do I need to create a web page into which I can POST the data - this seems so much trouble!

N

You can right click on a variable's watcher and select “Export”. However, this doesn't work on lists. You'll first need to convert it to text. (You can use the JOIN block by dropping the list over the little arrows.)
bharvey
Scratcher
1000+ posts

Snap! user discussion

hjcpps wrote:

Beyond lists, I can have a reference to a command script. This script can have a state, using the block variables experimental feature, or the “Local State with Script Variables” method described in section VIII.A of the manual. There isn't a way to copy this object (script reference plus local variable state) without writing my own copy constructor?
Right. Be aware that you're opening a can of worms, especially if you're later going to want to ask if two scripts are equal. I'm tempted to say that you should make a list with the script as its first item and the state variable as its second, and then you can RUN the script with the entire list as input, and you can mutate the second item of the list. A kludge, I guess, but avoids having to get the outer state just right.

bharvey
Scratcher
1000+ posts

Snap! user discussion

hjcpps wrote:

http://snap.berkeley.edu/run#present:Username=hjcpps&ProjectName=discuss_005&editMode
Indeed. I would change mutex by 1 as the very first instruction of MOVE. Then it can do its testing, where mutex=2 is the desired state. If mutex>2, delay.

But really I would solve this problem totally differently, with a queue:


etc. Then just have one motion loop that pulls item 1 off of the queue repeatedly.

hjcpps
New to Scratch
40 posts

Snap! user discussion

A queue sounds smarter. That leads to two more questions:

Functional programming lists are immutable. I see how that can make a stack. Can they be used to make a queue?

Is there an efficient way for this motion loop to wait when the queue is empty? The “wait until <__>” block probably just polls. I don't see a “wait until message received” block (other than the hat blocks). I could shut down the motion loop thread when the queue is empty, and then restart it upon a first item being added to the queue.
bharvey
Scratcher
1000+ posts

Snap! user discussion

hjcpps wrote:

Functional programming lists are immutable. I see how that can make a stack. Can they be used to make a queue?
Sure. ENQUEUE (value) (queue) is just APPEND (queue) (LIST (value)), and DEQUEUE is the same as POP.

Is there an efficient way for this motion loop to wait when the queue is empty? The “wait until <__>” block probably just polls. I don't see a “wait until message received” block (other than the hat blocks). I could shut down the motion loop thread when the queue is empty, and then restart it upon a first item being added to the queue.
Make sure to pick “Thread safe scripts” in the options menu. Then the queue-reading script can just STOP itself when the queue empties, and it can have WHEN I RECEIVE at the top, and the scripts that enqueue events can just BROADCAST . (Thread safe scripts means that if another broadcast happens while the script is running, the new event is just ignored, instead of starting over from the beginning of the script, which is the default behavior we inherited from Scratch.)

nigeldodd
Scratcher
14 posts

Snap! user discussion

cycomachead wrote:

nigeldodd wrote:

Sorry if this has been answered already. I need to get (flat list) data out of a Snap program. I appreciate Javascript deliberate limitations of browser based programs so understand why it is difficult, but I can't even seem to get a block of numbers to copy and paste into something else.

What is the workaround for this, please? Do I need to create a web page into which I can POST the data - this seems so much trouble!

N

You can right click on a variable's watcher and select “Export”. However, this doesn't work on lists. You'll first need to convert it to text. (You can use the JOIN block by dropping the list over the little arrows.)


Yes, thank you, that is they way to do it. I had not spotted the right-click menu on strings to have this facility. And list conversion to string works as you say.

But when I try to do it the other way - import a string and assign it to a list

https://photos.app.goo.gl/U83nKMtfhU8rInFR2

set inStringList to list(split(outstring by letter))

the result is a horizontal list, not a vertical list as it was when I started out. How can I transpose the list?
Jonathan50
Scratcher
1000+ posts

Snap! user discussion

Because you're putting the SPLIT block into a LIST block, it makes a one-item list that contains just the list SPLIT gave you. Snap! shows that as a table with one row. Taking out the LIST block (and keeping just the SPLIT) should fix it.

Last edited by Jonathan50 (June 5, 2018 11:12:58)


Not yet a Knight of the Mu Calculus.
nigeldodd
Scratcher
14 posts

Snap! user discussion

Jonathan50 wrote:

Because you're putting the SPLIT block into a LIST block, it makes a one-item list that contains just the list SPLIT gave you. Snap! shows that as a table with one row. Taking out the LIST block (and keeping just the SPLIT) should fix it.
It does fix it. Thanks.
Monniasza_spzoo
Scratcher
100+ posts

Snap! user discussion

I want 3D graphics library.
bharvey
Scratcher
1000+ posts

Snap! user discussion

Monniasza_spzoo wrote:

I want 3D graphics library.
Is there one for Scratch? It'll probably work in Snap! too.

hjcpps
New to Scratch
40 posts

Snap! user discussion

bharvey wrote:

hjcpps wrote:

Functional programming lists are immutable. I see how that can make a stack. Can they be used to make a queue?
Sure. ENQUEUE (value) (queue) is just APPEND (queue) (LIST (value)), and DEQUEUE is the same as POP.

Okay, I found it. Libraries…List utilities…Import to get the append block. Thank you!

hjcpps
New to Scratch
40 posts

Snap! user discussion

Minor issues with the <touching _sprite_ ?> and <touching _color_ ?> sensing blocks.

This example is brief and well commented.
http://snap.berkeley.edu/run#present:Username=hjcpps&ProjectName=discuss_004&editMode
xly
Scratcher
100+ posts

Snap! user discussion

Monniasza_spzoo wrote:

I want 3D graphics library.

Look at this : http://www.xleroy.net/ByobTuto/Beetleblocks/beetleblocks.html
bharvey
Scratcher
1000+ posts

Snap! user discussion

hjcpps wrote:

Minor issues with the <touching _sprite_ ?> and <touching _color_ ?> sensing blocks.
Indeed.

Your project behaves differently for me if I turn off retina support. (Still not perfect, but different.) So this is an off-by-one issue somewhere. Thanks for reporting it.

scratchmouse
Scratcher
70 posts

Snap! user discussion

I have sixteen sprites, each having local variables named “x_list” and “y_list” containing too many data (i.e. the lists are too long and I need to delete items so that at the end the number of items will be 15, which is how many costumes have a sprite named “Frames”).

So, every one of (those local) “x_list”s and “y_list”s, belonging to aforementioned sixteen sprites, needs to be of the same length (i.e. not more than is the number of costumes of “Frames”).



When I have seen the Brian's solution with putting ringified commands into a variable/list, I have tried to make something similar, but in my case the “list of commands” put into a variable/list does not work.

I then tried to use a <“for each item of” a list of sprites>, but this didn't work, either.

Only the “loop version” works as intended, which keeps deleting the <z_th> item until all the items of local “x_list”s and “y_list”s that needed to be deleted have been deleted. Why did the other solutions not work?

bharvey wrote:

…But really I would solve this problem totally differently…:


Last edited by scratchmouse (June 8, 2018 14:12:50)


˙˙˙ ˙˙ ˙Ignore˙ ˙˙ ˙˙˙

… .. ˇˇˇ ˇˇˇ ˇˇˇ ˇˇˇ .. …
::: :: … ˇˇˇ ˇˇˇ … :: :::
CSTeacherAP
New to Scratch
3 posts

Snap! user discussion

Hosting SNAP locally.
Hi, I'm hosting snap locally inside my school's LAN on a webserver.
My question:

Is there a way of hosting the costumes and sounds, tools, so that students do not have to access Berkley's external server each time? Also, I'd like to add my own costumes, so I guess I'm asking if I can create a local repo for costumes, sounds, backgrounds? What line of code in SNAP should I look at?

Thanks in advance!

Powered by DjangoBB