This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2010-04-12 00:25:47

Sloshylucas97
Scratcher
Registered: 2010-03-19
Posts: 8

Variables Help Needed! - Min and Max limits

Hi to all,

I was wondering if there was any was to set a min and max limit to any given variable. I know that you can set a slider min and max to the variables with the slider layout but i want to know if you actually set a min and max number to a variable.

Thanks in advance.


http://www.danasoft.com/sig/Sloshylucas.jpg

Offline

 

#2 2010-04-12 00:47:33

Chrischb
Scratcher
Registered: 2008-07-24
Posts: 1000+

Re: Variables Help Needed! - Min and Max limits

You can't...  sad


I fall: It's a tragedy. You fall: It's comedy.
Hmph enjoy your fall - I get a lovely spring... without pans of new leaves.

Offline

 

#3 2010-04-12 00:56:49

hmnwilson
Scratcher
Registered: 2007-07-04
Posts: 1000+

Re: Variables Help Needed! - Min and Max limits

There's no setting for that, but you can do it manually.

For example, say you want the minimum to be 1 and the max to be 10. You could just use this script:

<forever>
  <if><( <{ variable }> <>> 10 )>
    <set{ variable }to( 10
  <end>
  <if><( <{ variable }> <<> 1 )>
    <set{ variable }to( 1
  <end>
<end>

[/blocks]With that script, it could never go outside of 1-10.


I'm taking a break from Scratch until 2.0 comes out. Any messages sent between then and now probably won't be read - sorry.
(Oct. 20, 2011)

Offline

 

#4 2010-04-12 06:36:00

Sloshylucas97
Scratcher
Registered: 2010-03-19
Posts: 8

Re: Variables Help Needed! - Min and Max limits

Thanks hmnwilson, it worked like a charm.  smile


http://www.danasoft.com/sig/Sloshylucas.jpg

Offline

 

#5 2010-04-12 07:39:35

Phi_Lho
Scratcher
Registered: 2010-03-22
Posts: 75

Re: Variables Help Needed! - Min and Max limits

Just use the mod operator...
Mmm, although it depends on the behavior you expect from this variable.
mod constraints the content of variable to be within given bounds.
But maybe you prefer to get max value if above max, min value if below min. In this case, a simple double if should do the trick, as shown...

Last edited by Phi_Lho (2010-04-12 12:14:41)


http://i241.photobucket.com/albums/ff159/PhiLho/KM150.pnghttp://i241.photobucket.com/albums/ff159/PhiLho/PhiLhoLogo.png

Offline

 

#6 2010-04-12 11:56:31

Phi_Lho
Scratcher
Registered: 2010-03-22
Posts: 75

Re: Variables Help Needed! - Min and Max limits

Just made a little project to illustrate my idea. Which was not as trivial as I thought with the added constraint to leave values in bound unchanged...
See ShowMODOperator which is a bit clumsy because I know no other way to display text on screen...
I recommend instead to download the project and see what is inside! :-)


http://i241.photobucket.com/albums/ff159/PhiLho/KM150.pnghttp://i241.photobucket.com/albums/ff159/PhiLho/PhiLhoLogo.png

Offline

 

#7 2010-04-12 12:05:18

markyparky56
Scratcher
Registered: 2008-03-20
Posts: 1000+

Re: Variables Help Needed! - Min and Max limits

Phi_Lho wrote:

Just use the mod operator...
Mmm, although it depends on the behavior you expect from this variable.
mod constraints the content of variable to be within given bounds.
But maybe you prefer to get max value if above max, min value if below min. In this case, a simple double if should do the trick (no loop needed).

Why make things more complex when you can do it with what has already been suggested?


http://j.mp/jgVnTq
Check out my game engine development site: NewDawn I'm a Level 171 Scratcher.I am http://bit.ly/nkvLNT

Offline

 

#8 2010-04-12 12:18:28

Phi_Lho
Scratcher
Registered: 2010-03-22
Posts: 75

Re: Variables Help Needed! - Min and Max limits

I answered a different use case.
The first solution caps the variable. Which is probably what the original poster expected.
My solution results in a value that still evolves, within the given bounds: when the value goes from 101 to 110, the result varies from 1 to 10.
It can be interesting too, in some cases. For example to constraint list access to a given range.

Last edited by Phi_Lho (2010-04-12 12:25:57)


http://i241.photobucket.com/albums/ff159/PhiLho/KM150.pnghttp://i241.photobucket.com/albums/ff159/PhiLho/PhiLhoLogo.png

Offline

 

#9 2010-04-12 12:26:16

markyparky56
Scratcher
Registered: 2008-03-20
Posts: 1000+

Re: Variables Help Needed! - Min and Max limits

Phi_Lho wrote:

I answered a different use case.
The first solution caps the variable. Which is probably what the original poster expected.
My solution results in a value that still evolves, within the given bounds: when the value goes from 101 to 110, the result varies from 1 to 10.
It can be interesting too, in some cases. For example to constraint list access to a given range.

Evolves?


http://j.mp/jgVnTq
Check out my game engine development site: NewDawn I'm a Level 171 Scratcher.I am http://bit.ly/nkvLNT

Offline

 

#10 2010-04-12 13:48:53

Doody
Scratcher
Registered: 2008-10-27
Posts: 500+

Re: Variables Help Needed! - Min and Max limits

markyparky56 wrote:

Phi_Lho wrote:

I answered a different use case.
The first solution caps the variable. Which is probably what the original poster expected.
My solution results in a value that still evolves, within the given bounds: when the value goes from 101 to 110, the result varies from 1 to 10.
It can be interesting too, in some cases. For example to constraint list access to a given range.

Evolves?

He means when it changes I think...evolution is when you change or something...


(Insert signature here)

Offline

 

#11 2010-04-12 13:56:59

markyparky56
Scratcher
Registered: 2008-03-20
Posts: 1000+

Re: Variables Help Needed! - Min and Max limits

Doody wrote:

markyparky56 wrote:

Phi_Lho wrote:

I answered a different use case.
The first solution caps the variable. Which is probably what the original poster expected.
My solution results in a value that still evolves, within the given bounds: when the value goes from 101 to 110, the result varies from 1 to 10.
It can be interesting too, in some cases. For example to constraint list access to a given range.

Evolves?

He means when it changes I think...evolution is when you change or something...

Evolution means that it changes, yes, but i dont know why its being used in that context.


http://j.mp/jgVnTq
Check out my game engine development site: NewDawn I'm a Level 171 Scratcher.I am http://bit.ly/nkvLNT

Offline

 

#12 2010-04-13 05:35:31

Paddle2See
Scratch Team
Registered: 2007-10-27
Posts: 1000+

Re: Variables Help Needed! - Min and Max limits

Phi_Lho wrote:

I answered a different use case.
The first solution caps the variable. Which is probably what the original poster expected.
My solution results in a value that still evolves, within the given bounds: when the value goes from 101 to 110, the result varies from 1 to 10.
It can be interesting too, in some cases. For example to constraint list access to a given range.

It looks to me like it might be useful for mapping a sprite position into a given set of virtual boundaries, like with an infinite scroller.  It could be very handy.   smile


http://i39.tinypic.com/2nav6o7.gif

Offline

 

#13 2010-04-13 08:12:08

Phi_Lho
Scratcher
Registered: 2010-03-22
Posts: 75

Re: Variables Help Needed! - Min and Max limits

markyparky56 wrote:

Evolution means that it changes, yes, but i dont know why its being used in that context.

Because I am French and usage of this word makes more sense in French (in this context) than in English... :-) I will remember that (I hope!).
Or say I wanted to mean the value mutates? (:-P Doesn't make more sense, I fear... :-D Although in computing science we distinguish mutable variables, whose content/value can change, from immutable ones, also known as constants.)

Last edited by Phi_Lho (2010-04-13 08:14:59)


http://i241.photobucket.com/albums/ff159/PhiLho/KM150.pnghttp://i241.photobucket.com/albums/ff159/PhiLho/PhiLhoLogo.png

Offline

 

#14 2010-04-13 10:23:05

markyparky56
Scratcher
Registered: 2008-03-20
Posts: 1000+

Re: Variables Help Needed! - Min and Max limits

Phi_Lho wrote:

markyparky56 wrote:

Evolution means that it changes, yes, but i dont know why its being used in that context.

Because I am French and usage of this word makes more sense in French (in this context) than in English... :-) I will remember that (I hope!).
Or say I wanted to mean the value mutates? (:-P Doesn't make more sense, I fear... :-D Although in computing science we distinguish mutable variables, whose content/value can change, from immutable ones, also known as constants.)

How about changes? Mutates, to me, is where something goes wrong and it grows extra arms and legs or something.


http://j.mp/jgVnTq
Check out my game engine development site: NewDawn I'm a Level 171 Scratcher.I am http://bit.ly/nkvLNT

Offline

 

#15 2010-04-13 11:10:55

technoguyx
Scratcher
Registered: 2008-10-18
Posts: 1000+

Re: Variables Help Needed! - Min and Max limits

markyparky56 wrote:

Phi_Lho wrote:

markyparky56 wrote:

Evolution means that it changes, yes, but i dont know why its being used in that context.

Because I am French and usage of this word makes more sense in French (in this context) than in English... :-) I will remember that (I hope!).
Or say I wanted to mean the value mutates? (:-P Doesn't make more sense, I fear... :-D Although in computing science we distinguish mutable variables, whose content/value can change, from immutable ones, also known as constants.)

How about changes? Mutates, to me, is where something goes wrong and it grows extra arms and legs or something.

Yep, mutation and evolution are often associated to live beings changing. Changes would be a better word for the variable  smile

Last edited by technoguyx (2010-04-13 11:11:11)


http://getgnulinux.org/links/en/linuxliberated_4_78x116.png

Offline

 

#16 2010-04-13 11:21:21

markyparky56
Scratcher
Registered: 2008-03-20
Posts: 1000+

Re: Variables Help Needed! - Min and Max limits

technoguyx wrote:

markyparky56 wrote:

Phi_Lho wrote:


Because I am French and usage of this word makes more sense in French (in this context) than in English... :-) I will remember that (I hope!).
Or say I wanted to mean the value mutates? (:-P Doesn't make more sense, I fear... :-D Although in computing science we distinguish mutable variables, whose content/value can change, from immutable ones, also known as constants.)

How about changes? Mutates, to me, is where something goes wrong and it grows extra arms and legs or something.

Yep, mutation and evolution are often associated to live beings changing. Changes would be a better word for the variable  smile

Wow, you edited that at 11:11:11 ! :Lol:
It makes more sense with changes.


http://j.mp/jgVnTq
Check out my game engine development site: NewDawn I'm a Level 171 Scratcher.I am http://bit.ly/nkvLNT

Offline

 

Board footer