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.
Offline
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.
Offline
Thanks hmnwilson, it worked like a charm.
Offline
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)
Offline
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! :-)
Offline
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?
Offline
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)
Offline
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?
Offline
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...
Offline
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.
Offline
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.
Offline
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)
Offline
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.
Offline
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
Last edited by technoguyx (2010-04-13 11:11:11)
Offline
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
![]()
Wow, you edited that at 11:11:11 ! :Lol:
It makes more sense with changes.
Offline