Discuss Scratch

Jonathan50
Scratcher
1000+ posts

Snap! user discussion

vgbonilla wrote:

@Jonathan50, I've downloaded your websocket project and installed it on my custom server. I serve Snap! with your websocket enhancement. I connect via "open websocket to ws/“ and I see the traffic on my server, my server upgrades the connection to websocket and then when O try to use ”send to websocket >", I get nothing. Would you be able to help me understand your code?

Thanks in advance,
Victor
Ok, I don't actually know much about how to use websockets, but the SEND block takes the websocket it is passed and uses the JavaScript .send method on it. You need to be sure to save the result of the OPEN WEBSOCKET block in a variable and then pass that to the second parameter of the send block, like this:
set [websocket v] to (open websocket to ws://[the address goes here] :: sensing)

send [Hello] to (websocket) :: sensing
and make sure you are listening for data on the server-side.

Last edited by Jonathan50 (Aug. 16, 2017 00:29:46)


ae2d2bcb-e9e3-4f9c-a847-290d71bd8bfd 222ec087-6694-42cf-8c41-064e9066f004
michael971
Scratcher
13 posts

Snap! user discussion

I'm trying to create multiple stages/backdrops and switch them in SNAP, I see that SCRATCH lets you change backdrops.
bharvey
Scratcher
1000+ posts

Snap! user discussion

michael971 wrote:

I'm trying to create multiple stages/backdrops and switch them in SNAP, I see that SCRATCH lets you change backdrops.


To get the TELL block, choose “Import tools” from the File menu. You can put a background name or number in the input slot.

(The reason for the roundabout notation using the RUN block is that the SWITCH TO COSTUME block's pulldown menu will have the sprite's costumes, not the stage's.)

Dale_Mahalko
New to Scratch
50 posts

Snap! user discussion

This does not work. I have no idea why. Apparently accessing data in multidimensioned arrays does not work the way I expect it should.

Image:
http://imgur.com/8LSLseU

Inside: Error
expecting list but getting number

—————–

How to do what I mean?

CLEAR
DIM ARRAY(96,16)
FOR I = 1 TO 96
FOR J = 1 TO 16
ARRAY(I,J) = I + J
NEXT J
NEXT I

——————–

Also, I want to randomly access cells without having to sequentially “Insert” to all cells linearly first. How do I do this?

DIM ARRAY%(96,16)
ARRAY%(95,13) = 3

_nix
Scratcher
500+ 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)


blog (it has art, code, and stuff)

If you post bring up my post on a topic you don't own, are you claiming that it's yours?
Dale_Mahalko
New to Scratch
50 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.

You won't convince somebody with annoying sarcasm; yet that's exactly what I probably just did in the post above.
_nix
Scratcher
500+ 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).

blog (it has art, code, and stuff)

If you post bring up my post on a topic you don't own, are you claiming that it's yours?
rdococ
Scratcher
100+ 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)


(ouo :: variables) // Meep!
This is my pet kumquat! Isn't he so CUTE?! I feed him signatures every day, and… wait, why are you looking at me like that?
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
100+ 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.

(ouo :: variables) // Meep!
This is my pet kumquat! Isn't he so CUTE?! I feed him signatures every day, and… wait, why are you looking at me like that?
_nix
Scratcher
500+ 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)


blog (it has art, code, and stuff)

If you post bring up my post on a topic you don't own, are you claiming that it's yours?
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
500+ 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

blog (it has art, code, and stuff)

If you post bring up my post on a topic you don't own, are you claiming that it's yours?
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
50 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
50 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.

Powered by DjangoBB

Standard | Mobile