Discuss Scratch

Killernotch101
Scratcher
100+ posts

Checking if a number is between two values.

I am making a 0 sprite button engine, (https://scratch.mit.edu/projects/196292786/#editor)
which works by checking where the mouse X and Y is when the stage is clicked, and checking if there is a “button” there.
The problem, is when I'm checking if the mouse X/Y is in-between the boundaries of a button. Basically, how do I check if that number is in between the two? (Did I say that twice?)
asivi
Scratcher
1000+ posts

Checking if a number is between two values.

For circular buttons you can check the distance from mouse to an specific point coordinates. Phytagoras.
Charles12310
Scratcher
1000+ posts

Checking if a number is between two values.

define get if (a) is between (b) and (c)
set [between? v] to <<(a) > (b)> and <(a) < (c)>>
SpaceDragon1
New Scratcher
100+ posts

Checking if a number is between two values.

if <<<([x pos v] of [Mouse v]) > [#]> and <([x pos v] of [Mouse v]) < [#]>> and <<[] > []> and <[] < []>>> then //same thing for y pos in blank spot

end
Does this help?
Please note that I cannot view your project (iPad), so this may not fit into your program.

(Note says “same thing for y pos in blank spot”)

Double ninja… :(

Last edited by SpaceDragon1 (Jan. 6, 2018 18:29:28)

Charles12310
Scratcher
1000+ posts

Checking if a number is between two values.

SpaceDragon1 wrote:

if <<<([x pos v] of [Mouse v]) > [#]> and <([x pos v] of [Mouse v]) < [#]>> and <<[] > []> and <[] < []>>> then //same thing for y pos in blank spot

end
Does this help?
Please note that I cannot view your project (iPad), so this may not fit into your program.

(Note says “same thing for y pos in blank spot”)

Double ninja… :(

Charles12310 wrote:

define get if (a) is between (b) and (c)
set [between? v] to <<(a) > (b)> and <(a) < (c)>>
This script is quicker.
SpaceDragon1
New Scratcher
100+ posts

Checking if a number is between two values.

Charles12310 wrote:

SpaceDragon1 wrote:

if <<<([x pos v] of [Mouse v]) > [#]> and <([x pos v] of [Mouse v]) < [#]>> and <<[] > []> and <[] < []>>> then //same thing for y pos in blank spot

end
Does this help?
Please note that I cannot view your project (iPad), so this may not fit into your program.

(Note says “same thing for y pos in blank spot”)

Double ninja… :(

Charles12310 wrote:

define get if (a) is between (b) and (c)
set [between? v] to <<(a) > (b)> and <(a) < (c)>>
This script is quicker.
But only finds it for one value, not two. Though you could easily modify it to have two. Either script works.
Killernotch101
Scratcher
100+ posts

Checking if a number is between two values.

Remember, these two numbers have to be interchangeable. As in, if
I clicked at X=-50 Y=50,
The button X=-100 to 100
The button Y=-100 to 100
You know one of the X's or Y's are negative, but you don't know which one. Is this possible in a equation?
Thanks for the current replies. You guys are really helpful!
when green flag clicked
set [ person] to [0]

when [ timer] > (10)
repeat (length of [ world census] :: list)
change [ person] by (1)
hug [person]

define hug [ person]
hug [person]
asivi
Scratcher
1000+ posts

Checking if a number is between two values.

Killernotch101 wrote:

Remember, these two numbers have to be interchangeable. As in, if
I clicked at X=-50 Y=50,
The button X=-100 to 100
The button Y=-100 to 100
You know one of the X's or Y's are negative, but you don't know which one. Is this possible in a equation?
Thanks for the current replies. You guys are really helpful!

You check for the little firstly and if in bounds do something,,else check for the larger.
Just remember that such method is for horizontal(X) and vertical(Y) sides.

Last edited by asivi (Jan. 6, 2018 23:47:35)

asivi
Scratcher
1000+ posts

Checking if a number is between two values.

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


It contains custom blocks for squared(horizontal/vertical) and circular boundaries, and the strategy you need for your buttons embeded inside others.

Last edited by asivi (Jan. 7, 2018 01:40:52)

Killernotch101
Scratcher
100+ posts

Checking if a number is between two values.

Thanks, @avisi
although I think I'm going to stick with square buttons.
Feigh10
Scratcher
19 posts

Checking if a number is between two values.

asivi wrote:

For circular buttons you can check the distance from mouse to an specific point coordinates. Phytagoras.

what?

set [ comprehension] to [0]
Kashu0205
Scratcher
1 post

Checking if a number is between two values.

Killernotch101 wrote:

I am making a 0 sprite button engine, (https://scratch.mit.edu/projects/196292786/#editor)
which works by checking where the mouse X and Y is when the stage is clicked, and checking if there is a “button” there.
The problem, is when I'm checking if the mouse X/Y is in-between the boundaries of a button. Basically, how do I check if that number is in between the two? (Did I say that twice?)
nerdloop330
Scratcher
100+ posts

Checking if a number is between two values.

Don't necropost, especially when the topic is already answered. Necroposting is to post on an old topic.
CatClawz_
Scratcher
500+ posts

Checking if a number is between two values.

Killernotch101 wrote:

I am making a 0 sprite button engine, (https://scratch.mit.edu/projects/196292786/#editor)
which works by checking where the mouse X and Y is when the stage is clicked, and checking if there is a “button” there.
The problem, is when I'm checking if the mouse X/Y is in-between the boundaries of a button. Basically, how do I check if that number is in between the two? (Did I say that twice?)
If you do something like
<[?] < [[Position]]>
<[?] > [[Position]]>
ideapad-320
Scratcher
1000+ posts

Checking if a number is between two values.

<<<(mouse x)>[xmin]>and<(mouse x)<[xmax]>>and<<(mouse y)>[ymin]>and<(mouse y)<[ymax]>>>
EXCLUSIVE(excludes the min and max values)
not<<<(mouse x)<[x min]>or<(mouse x)>[x max]>>or<<(mouse y)<[x min]>or<(mouse y)>[x max]>>>
INCLUSIVE(contains the min and max values)
x man and max and y min max should be replaced by their respective values.
legendary34678
Scratcher
1000+ posts

Checking if a number is between two values.

Hello! Please don't necropost on old topics. Thanks!

Powered by DjangoBB