is a variable max value in hslider/vslider possible??

Posted By: pjotr987

is a variable max value in hslider/vslider possible?? - 08/15/12 11:24

hi guys, i wounder if htere is a possibility to create a slider with hslider or vslider with variable maximum value.

hslider (x, y, len, bmap, min, max, var);
vslider (x, y, len, bmap, min, max, var);

is it possible to replace the max value by a variable?

thanks in advance



Posted By: MasterQ32

Re: is a variable max value in hslider/vslider possible?? - 08/15/12 11:38

you can just calculate yourself:

function getslider(var value, var slidmin, var slidmax, var mymin, var mymax)
{
return ((mymax - mymin) * (value - slidmin)) / (slidmax - slidmin) + mymin;
}
Posted By: pjotr987

Re: is a variable max value in hslider/vslider possible?? - 08/15/12 12:41

WOW, works perfectly !!

thanks man
Posted By: Ruben

Re: is a variable max value in hslider/vslider possible?? - 12/20/14 09:03

Originally Posted By: MasterQ32
you can just calculate yourself:

function getslider(var value, var slidmin, var slidmax, var mymin, var mymax)
{
return ((mymax - mymin) * (value - slidmin)) / (slidmax - slidmin) + mymin;
}

How would this work in finding a variable max value for hslider? Would you place this function in the "max" position of hslider, like so?:

Code:
hslider (x, y, len, bmap, min, getslider(), var);



???

Also, what is the difference between slidmin and mymin, or slidmax and mymax ?
Posted By: MasterQ32

Re: is a variable max value in hslider/vslider possible?? - 12/20/14 11:50

slidmin/slidmax is the minimum/maximum of your hslider, mymin/mymax the real minimum/maximum value you want to have.
you just need to carry a helper variable from the hslider to the slider evaluation
Posted By: Ruben

Re: is a variable max value in hslider/vslider possible?? - 12/20/14 12:18

So, lets say I have an hslider that looks like this ( itm_qnt_ent_from variable dynamically equals the dynamic max amount that I want for the hslider at any given time):

Code:
hslider(450, 514, 150, "horizontalSlider.pcx", 0, 1, itm_qnt_ent_from);



...and lets say I also have a function that looks like this:

Code:
function getslider(var value, var slidmin, var slidmax, var mymin, var mymax)
{
   return ((mymax - mymin) * (value - slidmin)) / (slidmax - slidmin) + mymin;
}



How would I use the getslider function? Would it be like this?:

Code:
int dynamicMaxValue = getslider(itm_qnt_ent_from, 0, 1, 0, itm_qnt_ent_from);

...

hslider(450, 514, 150, "horizontalSlider.pcx", 0, dynamicMaxValue, itm_qnt_ent_from);



Wouldn't the hslider function reject the dynamicMaxValue variable, because it does not accept variables for the max? I guess I am a little confused on how the getslider function would be applied.
Posted By: MasterQ32

Re: is a variable max value in hslider/vslider possible?? - 12/20/14 12:35

hslider(450, 514, 150, "horizontalSlider.pcx", 0, 100, helperVar);

var result = getslider(helperVar, 0, 100, 0, dynamicMaxValue);
Posted By: Ruben

Re: is a variable max value in hslider/vslider possible?? - 12/20/14 15:55

So, can helperVar and dynamicMaxValue be the same variable, like for example, itm_qnt_ent_from , or do they have to be different variables?

How would I use the "result" variable? Do I just let it sit there?
Posted By: Ruben

Re: is a variable max value in hslider/vslider possible?? - 12/20/14 16:04

Originally Posted By: MasterQ32
hslider(450, 514, 150, "horizontalSlider.pcx", 0, 100, helperVar);

var result = getslider(helperVar, 0, 100, 0, dynamicMaxValue);

I tried this, but I get the same result. The horizontal slider shows up, but it is allowing the range for the horizontal slider button to go from 0 all the way to 100, when the itm_qnt_ent_from variable only equals 4, which should be the current max value. If itm_qnt_ent_from ends up equaling 4, I only want the horizontal slider to go up to 4, and no higher. However, with the above configuration, the lowest amount at the far left will be 0, and the slider button will start off at 4, but the player is capable of moving the horizontal button all the way to 100, by moving the button to the far right.

In the above scenario, if the player moves the button to the far right, I only want the amount to be 4, and no higher. If the player moves the button to the far left, I want the amount to be 0, and no less.

If the itm_qnt_ent_from value changes, to lets say 7, then I want the horizontal slider to change when it is brought up, to being able to move the horizontal button to the far right making the amount equal 7, and no higher. And if the player moves the horizontal button to the far left, it should equal 0, and no less. In other words, I want the hslider to have a dynamic max value, based on the value of the itm_qnt_ent_from variable.
Posted By: MasterQ32

Re: is a variable max value in hslider/vslider possible?? - 12/20/14 16:46

yes i know what you want. But i don't think you get what i was writing several times now. Think about the code i've written. It doesn't work if you just plain stupid copy paste it. Code never works if you copy paste it.
Think about it. Think about what i am doing here. Just some hint:
http://en.wikipedia.org/wiki/Cross-multiplication
Posted By: Ruben

Re: is a variable max value in hslider/vslider possible?? - 12/22/14 06:19

Originally Posted By: MasterQ32
yes i know what you want. But i don't think you get what i was writing several times now. Think about the code i've written. It doesn't work if you just plain stupid copy paste it. Code never works if you copy paste it.
Think about it. Think about what i am doing here. Just some hint:
http://en.wikipedia.org/wiki/Cross-multiplication

Sorry, I really am trying to understand. So, if "result" ends up equaling a number after the getslider() computation, how exactly would I use the "result" variable for the hslider function? Doesn't the hslider function not accept a variable for the max argument, only a number that is not assigned to a variable?
Posted By: Ruben

Re: is a variable max value in hslider/vslider possible?? - 12/22/14 07:27

The manual for "hslider" makes no sense to me:

"For changing the slider range at runtime, use a min and max range of 0..1, and multiply var with the desired maximum value."

So, does this mean:

Code:
itm_qnt_ent_from = itm_qnt_ent_from * item_quant_entFrom; 
                  // with item_quant_entFrom being the 
                  //   desired max value, and itm_qnt_ent_from
                  //   being the helper variable.

...

hslider(450, 514, 150, "horizontalSlider.pcx", 0, 1, itm_qnt_ent_from);


?
© 2024 lite-C Forums