Discuss Scratch

NMario84
Scratcher
1000+ posts

Why can't you use 'edge' as a variable name to detection?

Say for example you have player sprite, object1 sprite, and object2 sprite (and so on).
You can set a variable to say ‘object1’, and you can touch said object.

when flag clicked
set [object name v] to [Object1]
forever
if <touching (object name) ?> then
... // Do stuff here.
end
end
In this case, it 'WILL' work.

However, setting the variable to ‘edge’……. It does 'NOT' work.
when flag clicked
set [object name v] to [edge]
forever
if <touching (object name) ?> then
... // Does NOT work.
end
end
Is this because ‘edge’ is not identified as an object, but more of a reference position?

and yes I already KNOW you can just use
<touching [edge v] ?>

But that is not the point here. My experiment with this was to create a single list of many possible obstacles to check the players collisions without duplicating too many codes. I added ‘edge’ into the list of possibilities, but it didn't do anything. Is there any work arounds, or do you absolutely HAVE to use the ‘touching (edge v)’ block by itself?
Scratch-Minion
Scratcher
1000+ posts

Why can't you use 'edge' as a variable name to detection?

If you create a sprite named edge, you will see that your code recognizes when the sprite edge is touched but not when the edge of the screen is touched. The dropdown box in the touching block will show the sprite edge and edge for the screen. They look identical.

So you will need to separately use the sensing block “touching edge” to detect when the edge of the screen is touched.
awesome-llama
Scratcher
1000+ posts

Why can't you use 'edge' as a variable name to detection?

NMario84
Scratcher
1000+ posts

Why can't you use 'edge' as a variable name to detection?

Oh wow, so they just added _'s before and after the word… That is interesting. Thanks for the info.
cloverfly
Scratcher
500+ posts

Why can't you use 'edge' as a variable name to detection?

NMario84 wrote:

Oh wow, so they just added _'s before and after the word… That is interesting. Thanks for the info.
you also can't name a sprite “_myself_”, “_edge_”, or “_stage_”
NMario84
Scratcher
1000+ posts

Why can't you use 'edge' as a variable name to detection?

cloverfly wrote:

NMario84 wrote:

Oh wow, so they just added _'s before and after the word… That is interesting. Thanks for the info.
you also can't name a sprite “_myself_”, “_edge_”, or “_stage_”

Ah that's interesting. Thanks for the info.
DuckEdits2021
Scratcher
73 posts

Why can't you use 'edge' as a variable name to detection?


Dynamic Collision with Sprite Name
when green flag clicked
set [object name v] to [Object1]
forever
if <touching (object name)> then
// do stuff here

(Does not work when using “edge”)
when green flag clicked
set [object name v] to [edge]
forever
if <touching (object name)> then
// this does NOT work

Workaround 1:
when green flag clicked
set [object name v] to [edge]
forever
if <(object name) = [edge]> then
if <touching [edge v]> then
// do stuff for touching edge
if <not <(object name) = [edge]>> then
if <touching (object name)> then
// do stuff for touching sprite


Workaround 2

when green flag clicked
set [object name v] to [EdgeCollider]
forever
if <touching (object name)> then
// treat as edge collision
```



Workaround 3
when green flag clicked
forever
if <(x position) > [240]> then
// touching right edge
if <(x position) < [-240]> then
// touching left edge
if <(y position) > [180]> then
// touching top edge
if <(y position) < [-180]> then
// touching bottom edge
```
NMario84
Scratcher
1000+ posts

Why can't you use 'edge' as a variable name to detection?

DuckEdits2021 wrote:

Dynamic Collision with Sprite Name
<scratchblocks>
```

Ummm…… Some of those are probably questionable (ex. using a sprite to detect edge), and otherwise don't make any sense. Using numbers/values to decide the edges “CAN” work in it's own little way, but can also be “finnicky” at times, and a little “too” precise. What I mean is, if you convert your project to work on a mod of Scratch that allows a new window screen size, you would have to change these numbers as well in order for your project to work on the size you need..

Anyway, I have already found my answer. So I will close the topic now.

Powered by DjangoBB