Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » something wrong with maximum and minimum
- fghjkld
-
Scratcher
36 posts
something wrong with maximum and minimum
I'm trying to make it so if a variable is in the maximum or minimum, something happens, but when i make the variable not in the maximum or minimum, it cancels. I tried doing this, but it just doesn't work
if <<(foo) > [172]> and <(foo) < [-172]>> then(reminder: when my variable goes past 180, it goes negative)
say [test]
else
end
- nose0224
-
Scratcher
8 posts
something wrong with maximum and minimum
What do you mean by cancels and “(reminder: when my variable goes past 180, it goes negative)”?
- fghjkld
-
Scratcher
36 posts
something wrong with maximum and minimum
basically, the action goes back to its previous state, and also when the variable goes past 180, it suddenly becomes -180 and descends instead of ascends
- MultiTasker801
-
Scratcher
100+ posts
something wrong with maximum and minimum
the scratchblocks you posted use <<> and <>> which will never be true because no number can be both larger than 172 and less than -172. you want <<> or<>>
- fghjkld
-
Scratcher
36 posts
something wrong with maximum and minimum
oh, thanks, but since the variable is set to the direction, it suddenly goes negative since it goes from 180 to -180 and 0 to -0
Last edited by fghjkld (Sept. 6, 2026 23:28:51)
- SpyCoderX
-
Scratcher
1000+ posts
something wrong with maximum and minimum
What exactly are you trying to do?
The switch from 180 to -180 is just a byproduct of the fact that a circle “starts” and “ends” on the same spot, so the numbers used to describe a position on the circle have to follow that fact too.
However, for most cases this isn’t an issue, since any angle-based calculations shouldn’t use the sprite’s direction as an input.
The switch from 180 to -180 is just a byproduct of the fact that a circle “starts” and “ends” on the same spot, so the numbers used to describe a position on the circle have to follow that fact too.
However, for most cases this isn’t an issue, since any angle-based calculations shouldn’t use the sprite’s direction as an input.
Last edited by SpyCoderX (Sept. 7, 2026 00:43:08)
- 10goto10
-
Scratcher
1000+ posts
something wrong with maximum and minimum
It sounds like there is a range of 173 to 180 and -173 to -180 where something other than the say block should be executed.
Maybe something like this?
Maybe something like this?
when @greenFlag clicked
go to [front v] layer
point in direction (0)
repeat (360)
if <([abs v] of (direction)::operators) \< [173]> then
say (direction)
turn @turnRight (1) degrees::motion
else
turn @turnRight (.5) degrees::motion
end
end
- fghjkld
-
Scratcher
36 posts
something wrong with maximum and minimum
What exactly are you trying to do?basically i am trying to recreate the microgame Hat's Off from warioware twisted
The switch from 180 to -180 is just a byproduct of the fact that a circle “starts” and “ends” on the same spot, so the numbers used to describe a position on the circle have to follow that fact too.
However, for most cases this isn’t an issue, since any angle-based calculations shouldn’t use the sprite’s direction as an input.
- 10goto10
-
Scratcher
1000+ posts
something wrong with maximum and minimum
what if I'm using a variable?Isn't the variable just set to the direction? If so then it is the same value.
It's probably better if you can share and link your project so we can narrow down how to help you.
- Scratch-Minion
-
Scratcher
1000+ posts
something wrong with maximum and minimum
I'm trying to make it so if a variable is in the maximum or minimum, something happens, but when i make the variable not in the maximum or minimum, it cancels. I tried doing this, but it just doesn't workif <<(foo) > [172]> and <(foo) < [-172]>> then(reminder: when my variable goes past 180, it goes negative)
say [test]
else
end
I think you just want an “or” rather than an “and”.
if <<(foo) > [172]> or <(foo) < [-172]>> then
say [test]
else
end
- fghjkld
-
Scratcher
36 posts
something wrong with maximum and minimum
it's not shared since it's not finished but here https://scratch.mit.edu/projects/1378397101/what if I'm using a variable?Isn't the variable just set to the direction? If so then it is the same value.
It's probably better if you can share and link your project so we can narrow down how to help you.
- 10goto10
-
Scratcher
1000+ posts
something wrong with maximum and minimum
It looks like you changed the “and” to an “or” but you also changed one of the comparisons, so your script is now
I put in my change and the hat seems to only say hello in that range of -172 to 172
when @greenFlag clicked
go to x\: (0) y\: (50)
forever
+ if <<(city direction) \> [-172]> or <(city direction) \> [172]>> then
say [Hello!]
else
end
end
I put in my change and the hat seems to only say hello in that range of -172 to 172
when @greenFlag clickedbut you might want to experiment with both ways to see what will actually work for you.
go to x\: (0) y\: (50)
forever
if <([abs v] of (city direction)::operators) \< [173]> then
say [Hello!]
else
say []
end
end
- ITS_DINO_XD
-
Scratcher
100+ posts
something wrong with maximum and minimum
if you want to cap the car then here's a simple script
when green flag clicked
forever
if <(your variable) > [172]> then
set [your variable v] to [172]
end
if <(your variable) < [-172]> then
set [your variable v] to [-172]
end
end
- fghjkld
-
Scratcher
36 posts
something wrong with maximum and minimum
It looks like you changed the “and” to an “or” but you also changed one of the comparisons, so your script is nowactually, this helped! thanks!when @greenFlag clicked
go to x\: (0) y\: (50)
forever
+ if <<(city direction) \> [-172]> or <(city direction) \> [172]>> then
say [Hello!]
else
end
end
I put in my change and the hat seems to only say hello in that range of -172 to 172when @greenFlag clickedbut you might want to experiment with both ways to see what will actually work for you.
go to x\: (0) y\: (50)
forever
if <([abs v] of (city direction)::operators) \< [173]> then
say [Hello!]
else
say []
end
end
- Discussion Forums
- » Help with Scripts
-
» something wrong with maximum and minimum