Discuss Scratch

_nix
Scratcher
1000+ posts

Snap! user discussion

Dale_Mahalko wrote:

This does not work. I have no idea why. Apparently accessing data in multidimensioned arrays does not work the way I expect it should.
See this project for my response. Read the left column first (everything to the left of the tall comment); it has all the Important™ information, and the answers to your questions. The other side is just technical stuff that I found interesting while writing out my response. It might help explain the left side better, or it might confuse you.

(Brian: I believe you can use #cloud:projectID instead of #present:projectID to open a project in editor mode?)

Last edited by _nix (Aug. 17, 2017 11:57:16)


══ trans autistic lesbian enbydoggirls // 16 17 18 19 20, she/they
sparrows one word to the paragraph // <3 // ~(quasar) nebula
Dale_Mahalko
New to Scratch
68 posts

Snap! user discussion

How do I clear all variables at program start? This retaining of data across each program run is tripping me up.
jokebookservice1
Scratcher
1000+ posts

Snap! user discussion

Dale_Mahalko wrote:

How do I clear all variables at program start? This retaining of data across each program run is tripping me up.
I suggest initialising the variables at the beggining like so

when green flag clicked
set [variable v] to [something]

That way, each time the green flag is clicked, the data resets.
_nix
Scratcher
1000+ posts

Snap! user discussion

Dale_Mahalko wrote:

How do I clear all variables at program start? This retaining of data across each program run is tripping me up.
(Definitely check Jokebook's answer for a way to clear the variable when the program runs; see this post for how to make the variable be clear when it's loaded/saved..)

Snap! actually has an option for this - right click on the variable and select the check box “transient”. That option prevents the variable's contents from being saved in the project file (so the variable will be empty when you load the project).

══ trans autistic lesbian enbydoggirls // 16 17 18 19 20, she/they
sparrows one word to the paragraph // <3 // ~(quasar) nebula
rdococ
Scratcher
500+ posts

Snap! user discussion

I'd like it if there was a parameter type which would enable the block to modify the variable passed to it. As an example, using two arrows “↓↑” to signify this type of variable:
(+ set + (x ↓↑) + to + 3 + :: stack grey) :: control hat
set [x v] to [3]

And if you, say, did this:
script variables (banana) :: grey
set (banana) to 3 :: grey
say (banana)
then the sprite would say 3 - because the block definition has the ability to modify the variable. It's like an upvar, except you must pass an existing variable, and the block will modify that and pass it back (hence the usage of ↓↑).

I'd attempt this myself, but I haven't quite acquainted myself with Snap!'s inner workings yet (if you point me to (or release if they don't exist yet) documents telling me and future Snap! modders how the program works, that would be wonderful).

EDIT: I did modify the source code, however, to put variables into the set variable block. I was able, then, to create a custom block that takes a ringified variable and modifies it. I wonder if I could convert such a block to JS, so putting variable reporters into the set block is not necessary (since, even if the ringified version was created outside the scope, overshadowing with another variable of the same name still causes the block to modify the overshadowing variable, rather than the overshadowed one it should refer to. This could probably also be fixed, though.)

Last edited by rdococ (Aug. 21, 2017 13:31:48)

BookOwl
Scratcher
1000+ posts

Snap! user discussion

@rdococ, I believe that what you are looking for are upvars, (see page 39)

who needs signatures
rdococ
Scratcher
500+ posts

Snap! user discussion

BookOwl wrote:

@rdococ, I believe that what you are looking for are upvars, (see page 39)
Oh, upvars are cool and all, but I want to be able to modify already existent variables from outside the block call. If you're familiar with other languages, it's like passing a parameter by reference, rather than by value. Using rings would work, provided you could fix the scoping issue I mentioned earlier.
_nix
Scratcher
1000+ posts

Snap! user discussion

rdococ wrote:

I wonder if I could convert such a block to JS, so putting variable reporters into the set block is not necessary (since, even if the ringified version was created outside the scope, overshadowing with another variable of the same name still causes the block to modify the overshadowing variable, rather than the overshadowed one it should refer to. This could probably also be fixed, though.)
Yeah, that's possible! This works: http://snap.berkeley.edu/snapsource/dev/snap.html#present:Username=florrie&ProjectName=references

Here's the code that powers it all:

// "context" is a Snap! Context object; Contexts are really just rings.
// "context.expression" is the actual variable block.
// "context.expression.blockSpec" is the name of the variable block.
// Try looking up the definition of VariableFrame in Snap!'s code to get a feel for how it works.
// "set reference value" code:
var variableName = context.expression.blockSpec
var variableFrame = context.variables.parentFrame
variableFrame.setVar(variableName, newVal, context.receiver)
// Note context.receiver here -- context.receiver is the actual sprite who owns the context, and by passing it we give Snap! the ability to do its sprite inheritance goodies (see the "Child" sprite).
// "get reference value" code:
var variableName = context.expression.blockSpec
var variableFrame = context.variables.parentFrame
return variableFrame.getVar(variableName)

Last edited by _nix (Aug. 21, 2017 18:27:13)


══ trans autistic lesbian enbydoggirls // 16 17 18 19 20, she/they
sparrows one word to the paragraph // <3 // ~(quasar) nebula
bharvey
Scratcher
1000+ posts

Snap! user discussion

No need for heroic measures. Just do this:

The input “var” is declared of type “any (unevaluated)”:

And then it works as desired, in regular old Snap!:

P.S. The use of RUN here may seem unintuitive, but it's the standard way in Snap! to overcome restrictions on what's allowed in an input slot:

Last edited by bharvey (Aug. 21, 2017 21:04:21)


_nix
Scratcher
1000+ posts

Snap! user discussion

bharvey wrote:

No need for heroic measures.
Oh, that's cool! I didn't really expect that to work, but I guess it's sort of what I did do with my JS code. I should have tried

══ trans autistic lesbian enbydoggirls // 16 17 18 19 20, she/they
sparrows one word to the paragraph // <3 // ~(quasar) nebula
xly
Scratcher
100+ posts

Snap! user discussion

For new Snap!ers my list of shared projects:

Link= http://snap.berkeley.edu/snapsource/snap.html#present:Username=xleroy&ProjectName=XXXX
with XXXX replaced by one of following project names :

102-antcleaner
104-labyroad
107-pandemia
108-balloons
109-flowers
110-fonts
118-mkcube
120-clonoop
120-foline
120-invadermove
120-snakeclo
120-snowfall
130-antsandeggs
130-oopantegg
It's more fun to compete (Gottlieb)
dev_in_spain
New to Scratch
4 posts

Snap! user discussion

HI,

I was wondering if there is any documentation about how to change the world view in Code? Specifically, what I want is a way to:
  1. Load an XML project from a URL (from Amazon's S3)
  2. Show the Runtime window only with a button below the runtime window to show the blocks
  3. When clicking on the button, show the blocks, either overlayed on the runtime window or hiding the runtime window and showing the blocks

Note: That the button could exist outside of the Snap UI, as long as I can change or swap out the Execution window for the blocks used.

Any pointers or help would be very much appreciated

Last edited by dev_in_spain (Aug. 28, 2017 18:29:22)

bharvey
Scratcher
1000+ posts

Snap! user discussion

dev_in_spain wrote:

  1. When clicking on the button, show the blocks, either overlayed on the runtime window or hiding the runtime window and showing the blocks
Hi. The sharing URL for shared projects already starts in presentation mode, which is what you want. For the button, I'd program it as a sprite with a WHEN I AM CLICKED that uses the “Provide getters and setters for all UI…” library to set Presentation mode to False.

Dale_Mahalko
New to Scratch
68 posts

Snap! user discussion

Collision detection appears to be unreliable. Very often my bullets pass right through the target and don't collide. Does anyone know why?

Snapipede v0.05
http://snap.berkeley.edu/snapsource/snap.html#present:Username=lhs-dmahalko&ProjectName=Snapipede%20v0.05

Also the key-down detection is annoying, instead of detecting key-down it is really detecting key-repeat from the keyboard. So the player's gun can't just start moving immediately when a key is pressed. Have to wait for “key down, delay before repeat starts, key then repeats”.

The repeat delay causes more annoyance when switching between keys, because you again have to keep waiting for the key delay to time out. “Right arrow (repeat delay) move right continuously. Space to fire (repeat delay) fire continuously. Right arrow (repeat delay) move right continuously. ”

And apparently multiple keypress detection does not work. When using separate “is key down?” detection events, can't move and fire at the same time.
Dale_Mahalko
New to Scratch
68 posts

Snap! user discussion

I am familiar with the usual main-loop lockstep design that doesn't use messaging between independent clone scripts or collision detection but instead stores objects in an array and checks collisions of bullets, etc, against objects stored in the array.

But….. I want to see if using only collision detection and message passing can work as well as doing it the “traditional” lockstep main loop route
bharvey
Scratcher
1000+ posts

Snap! user discussion

Dale_Mahalko wrote:

Collision detection appears to be unreliable. Very often my bullets pass right through the target and don't collide. Does anyone know why?
Yeah, fast-moving objects can make it all the way through in a single time quantum, before the display refresh cycle can happen, and so it's not noticed. The usual solution is to make the walls thicker, if it's that kind of collision. For bullets through an avatar I'm not sure what to suggest.

SimpleScratch
Scratcher
500+ posts

Snap! user discussion

Hi
I haven't used Snap much so this has probably been asked/answered a thousand times but why is there no visual difference between local and global variables in Snap?

or is it just my eyesight in my old age

Simon
Dale_Mahalko
New to Scratch
68 posts

Snap! user discussion

How do I select a color and then plot a single 1-pixel point?

It doesn't work to move a sprite and then just do “Pen Down / Pen Up”.

http://snap.berkeley.edu/snapsource/snap.html#present:Username=lhs-dmahalko&ProjectName=plot%20points

Dale_Mahalko
New to Scratch
68 posts

Snap! user discussion

When scanning the keyboard for keypresses, why can't I detect UPPERCASE, the space bar, or any symbols `~!@#$%^&*()-=_+\{}|;':",./<> ….?

This does not work as I would expect.

http://snap.berkeley.edu/snapsource/snap.html#present:Username=lhs-dmahalko&ProjectName=Detect%20any%20keypress
bharvey
Scratcher
1000+ posts

Snap! user discussion

SimpleScratch wrote:

why is there no visual difference between local and global variables in Snap?
You mean sprite-local variables, or procedure-local ones?

There is a difference in the variable watchers on the stage – the label says if it's local. I guess we should put some visual representation of sprite-localness in the palette, maybe a little picture of the sprite next to the orange blob. My feeling is that actual code, where a variable is used, is already pretty crowded. Maybe we should compromise, and when you right-click an orange blob the menu should tell you what flavor it is.

Powered by DjangoBB