Discuss Scratch

BossRushFanatic
New Scratcher
54 posts

What's the difference between these two?

So I've been working on a project for quite a while and one of the things I use whenever I need something on the project to happen are variables combined with the blank equal blank blocks (Like this)

<(Variable) = []>

And some of the ways I use these are like the message blocks (these ones)

when I receive [Message v]

So I just never used the message blocks because I found an alternative for them but now that my project has gotten a little more complex I have been getting more errors with the alternative I used. For example for some reason the animations of the character you control get overlapped with other animations because of this alternative cuz some of these blocks have the same message. So for example if I made one that is like this

if <(InAir?) = [yes]> then

end

all good so far but when I add this to other stuff for like when jumping or crouching I think the game just activates them all instead of the one I want. My way to fix it was to add like checking blocks so instead of just the one I made of InAir it also has like if touching floor and other stuff to make it more specific of what you have to do in order for this to happen but i think i've made the project MORE complicated cuz many blocks just have MULTIPLE checks that's why I wanted to ask what does a message block do? And will they be useful for what I'm trying to fix?

Anyway sorry if this doesn't makes that much sense. It's kinda hard to explain it tbh. Anyway thank you and have a wonderful day! ^^
Woodfur
Scratcher
100+ posts

What's the difference between these two?

“When I receive (message)” triggers when some other block runs “broadcast (message)”. That's really it. They have lots of applications.

When a script in one sprite needs to trigger code in the same sprite, you can usually just directly run that code. But if you need to trigger code in a different sprite or clone, the direct way to do that is a broadcast.

“Wait until <condition>” and “if <condition>” are fine if that condition was already going to change, but if you've made a whole variable just so one sprite can keep checking its value, there's almost always a better way, and often that's a broadcast.
BossRushFanatic
New Scratcher
54 posts

What's the difference between these two?

Woodfur wrote:

“When I receive (message)” triggers when some other block runs “broadcast (message)”. That's really it. They have lots of applications.

When a script in one sprite needs to trigger code in the same sprite, you can usually just directly run that code. But if you need to trigger code in a different sprite or clone, the direct way to do that is a broadcast.

“Wait until <condition>” and “if <condition>” are fine if that condition was already going to change, but if you've made a whole variable just so one sprite can keep checking its value, there's almost always a better way, and often that's a broadcast.
Got it! Thank you so much! ^^
BossRushFanatic
New Scratcher
54 posts

What's the difference between these two?

Woodfur wrote:

“When I receive (message)” triggers when some other block runs “broadcast (message)”. That's really it. They have lots of applications.

When a script in one sprite needs to trigger code in the same sprite, you can usually just directly run that code. But if you need to trigger code in a different sprite or clone, the direct way to do that is a broadcast.

“Wait until <condition>” and “if <condition>” are fine if that condition was already going to change, but if you've made a whole variable just so one sprite can keep checking its value, there's almost always a better way, and often that's a broadcast.
Also just a quick question. Which one is more reliable for key inputs? This one:
if <key [z v] pressed?> then

end

or this one?
when [ v] key pressed

I think both of these do the same but I don't know if that's actually complete true. Thank you and have a good day! ^^
malicondii
Scratcher
100+ posts

What's the difference between these two?

BossRushFan wrote:

Also just a quick question. Which one is more reliable for key inputs? This one:
if <key [z v] pressed?> then

end

or this one?
when [ v] key pressed

I think both of these do the same but I don't know if that's actually complete true. Thank you and have a good day! ^^
After a quick test, both
forever
if <key [z v] pressed?> then

end
end
and
when [z v] key pressed
work at the same speed, so it's really just up to preference. (yes, they do the same thing)

Edit: after a little more testing it seems that the
when [z v] key pressed
works a little faster when pressing the same key alot.

Last edited by malicondii (Aug. 21, 2024 21:54:43)

BossRushFanatic
New Scratcher
54 posts

What's the difference between these two?

malicondii wrote:

BossRushFan wrote:

Also just a quick question. Which one is more reliable for key inputs? This one:
if <key [z v] pressed?> then

end

or this one?
when [ v] key pressed

I think both of these do the same but I don't know if that's actually complete true. Thank you and have a good day! ^^
After a quick test, both
forever
if <key [z v] pressed?> then

end
end
and
when [z v] key pressed
work at the same speed, so it's really just up to preference. (yes, they do the same thing)

Edit: after a little more testing it seems that the
when [z v] key pressed
works a little faster when pressing the same key alot.
Ah ok. Thank you so much for letting me know! ^^
DARDUDE
Scratcher
5 posts

What's the difference between these two?

https://scratch.mit.edu/projects/1058578817/

there is a little difference in the keys, just sometimes you cant do 2 at once. Not usually a problem if you just want to change backdrop, for example.
see the above project.
deck26
Scratcher
1000+ posts

What's the difference between these two?

But if you use

when [ v] key pressed

and just hold the key down you'll find a short delay between the first detection of the key and the subsequent ones. Think about what happens in things like Notepad if you press and hold a key - it shows the first character and then delays briefly before displaying a regular stream of the character. If that's an issue the

if <key [ v] pressed?> then

end
is better since it doesn't show this behaviour..
Woodfur
Scratcher
100+ posts

What's the difference between these two?

The hat block is useful if you need it to trigger immediately regardless of what any other script is doing. Checking in a loop is useful if you need something to happen the entire time the key is pressed. If you need both, you can combine them like this:

when [ v] key pressed
repeat until <not <key [ v] pressed?>>
do stuff
end
BossRushFanatic
New Scratcher
54 posts

What's the difference between these two?

Got it, Thank you so much y'all for the help! ^^
AHypnoman
Scratcher
1000+ posts

What's the difference between these two?

BossRushFanatic wrote:

~Snip~
Also just a quick question. Which one is more reliable for key inputs? This one:
if <key [z v] pressed?> then

end

or this one?
when [ v] key pressed

I think both of these do the same but I don't know if that's actually complete true. Thank you and have a good day! ^^

There is a fairly important difference here if any of your projects are laggy: the ‘if’ version of this, assuming it's in a loop, won't always run if you press it between loop iterations, which is near impossible to do if your project is going at full 30 fps but if things start lagging it can be really unreliable. The when pressed block is triggered by a key press rather than checking for a key currently being down, so will always reliably detect a keypress, but like has already been stated in this thread, it has other major drawbacks.

The ‘if’ block here is almost always better, because it doesn't have the same constraints (like a delay and it being a hat block), however if you can use the hat block and you're working on a big and laggy project, do (so long as you don't have to compromise on function)
BossRushFanatic
New Scratcher
54 posts

What's the difference between these two?

AHypnoman wrote:

BossRushFanatic wrote:

~Snip~
Also just a quick question. Which one is more reliable for key inputs? This one:
if <key [z v] pressed?> then

end

or this one?
when [ v] key pressed

I think both of these do the same but I don't know if that's actually complete true. Thank you and have a good day! ^^

There is a fairly important difference here if any of your projects are laggy: the ‘if’ version of this, assuming it's in a loop, won't always run if you press it between loop iterations, which is near impossible to do if your project is going at full 30 fps but if things start lagging it can be really unreliable. The when pressed block is triggered by a key press rather than checking for a key currently being down, so will always reliably detect a keypress, but like has already been stated in this thread, it has other major drawbacks.

The ‘if’ block here is almost always better, because it doesn't have the same constraints (like a delay and it being a hat block), however if you can use the hat block and you're working on a big and laggy project, do (so long as you don't have to compromise on function)
Got it. Thank you so much!!
graysprunkiboi
Scratcher
1 post

What's the difference between these two?

are blocks in scratch the same as messages? just asking!
DidntMeanToDoThat
Scratcher
500+ posts

What's the difference between these two?

In future you should create your own topic, but for now, specifically what do you mean? Comments, or these:
broadcast [message1 v]

Powered by DjangoBB