hslider max value?

Posted By: Ruben

hslider max value? - 08/12/14 07:57

I am trying to create a horizontal slider button and bar, but have its max value change at run-time, depending on the value of a certain variable that may change.

In my game, I have it programmed so that if the player gets within a certain distance of a treasure chest or dead body, the player can press the "m" key, which will bring up the mouse cursor, and if the player clicks on the treasure chest or the dead body with the mouse cursor, both the player's inventory bag and the chest's inventory bag will show up on the screen, or the player's inventory bag and the dead body's inventory bag will show up on the screen, the idea being that the player can transfer item(s) to and from the treasure chest, or to and from a dead body.

If there are five swords in an inventory bag, only one image of a sword will display in the inventory bag, instead of five sword images. If you the player click on that one image of the sword, a set of information about that item will show up on the right side of the screen, showing how much of that item (sword quantity) is in that particular inventory bag.

If you the player want to transfer 3 swords to a treasure chest (even though you have 5 swords in your inventory), I want to make it so that if you the player drag the sword image from your inventory bag to the treasure chest's inventory bag, a message will come up asking you how many of that item you want to transfer, along with a horizontal slider bar, and a "Transfer" button. The horizontal slider bar's maximum value toward the far right should equal the maximum amount of swords that the player is capable of transferring at the present time (for example, 5 swords). The player can then slide the horizontal bar left or right, which decreases or increases the quantity of the item that she/he would like to transfer. Once the player leaves the horizontal slider button at a certain quantity value to transfer, and presses the "Transfer" button, the chosen quantity of that item to transfer (chosen by the horizontal slider button) should transfer to the treasure chest's inventory bag, and the remaining amount should go back to the player's inventory bag.

I am trying to use the hslider function to do this. However, I am confused as how to change the hslider's max value at run-time to equal the maximum amount of a particular item that the player is capable of transferring at a given time (for example, 5 swords). As of now, it only looks like the hslider's max value has to be hard-coded as a number (instead of a variable that can change) into the hslider's max value. I want the hslider's max value to equal the value of the variable that represents the maximum quantity of a particular item that the player is trying to transfer at a given time.

For example, I try to change the hslider's max value at run-time, by doing this:

Code:
hslider(450, 514, 150, "horizontalSlider.pcx", 0, item_quant_entFrom, transf_amt); // I get error from using
   //   the item_quant_entFrom variable.



...instead of this

Code:
hslider(450, 514, 150, "horizontalSlider.pcx", 0, 50, transf_amt); // I get no errors, but I am stuck with 50 as
   //    the hslider's maximum value that it can slide 
   //    toward the right to.



...but I get an error when I assign a variable to the max value, instead of hard coding it with an actual integer (like 50). However, I want this hslider max value to be dynamic, not static.

Here is what the code for my horizontal slider button and bar looks like so far:

Code:
...

TEXT* invTransferText =
{
	layer = 10;
	pos_x = 350;
	pos_y = 490;
	string ("HOW MUCH OF ITEM DO YOU WANT TO TRANSFER?: ");
}

PANEL* horizontalSliderBar =
{
	layer = 0;
	
	bmap = "horizSliderBar.pcx";
	pos_x = 440;
	pos_y = 508;
}

PANEL* invTransferAmount =
{
	layer = 1;
	
	hslider(450, 514, 150, "horizontalSlider.pcx", 0, 50, transf_amt);
	digits (590, 490, 5, *, 1, transf_amt);
	button(640, 510, "transfer_button_click.pcx", "transfer_button.pcx", "transfer_button_hover.pcx",
	       transferItems, NULL, NULL);
}

...



Does anyone know how to make the hslider max value dynamic, instead of static, so that it can change at run-time, depending on the value of a certain variable?
Posted By: MasterQ32

Re: hslider max value? - 08/12/14 10:53

easy:

use a slider value going from 0 to 1 or 0 to 100, then use this slider variable to define your own dynamic values:

value = slider_min + slider_value * (slider_max - slider_min);
Posted By: txesmi

Re: hslider max value? - 08/12/14 12:08

or use 'pan_setslider' to modify the constants of the slider.
Posted By: Ruben

Re: hslider max value? - 08/13/14 06:10

Originally Posted By: MasterQ32
easy:

use a slider value going from 0 to 1 or 0 to 100, then use this slider variable to define your own dynamic values:

value = slider_min + slider_value * (slider_max - slider_min);

For this hslider function call:

Code:
hslider(450, 514, 150, "horizontalSlider.pcx", 0, 50, transf_amt);


...would I replace the "value" variable you spoke of where the "transf_amt" variable is?

For example:

Code:
...

value = slider_min + slider_value * (slider_max - slider_min);

hslider(450, 514, 150, "horizontalSlider.pcx", 0, 50, value); 

...



...or would the "value" variable go in the max location instead, as shown here?:

Code:
...

value = slider_min + slider_value * (slider_max - slider_min);

hslider(450, 514, 150, "horizontalSlider.pcx", 0, value, transf_amt); 

...



???
Posted By: sivan

Re: hslider max value? - 08/13/14 11:06

define a global var variable, for example one to be adjusted between -100 and 100 with the default value of 0:
Code:
var variable_to_adjust = 0;


within a function create your panel e.g. on layer 10, the size of the bmap will determine whether a hirozontal or vertical is created:
Code:
your_panel = pan_create(panel_background_bmp, 10):


you can add digits, sliders etc.
Code:
pan_setdigits(your_panel, 0,	15,80,	"Value: %0.f",	panel_font,		1, 		variable_to_adjust);
pan_setslider(your_panel, 0,	125,80,	horiz_slider_bmp, slider_knob_bmp,	-100,100,	variable_to_adjust);

Posted By: Ruben

Re: hslider max value? - 08/14/14 08:13

I am a bit confused on what the Help manual states about hslider:

"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 in the case of:
Code:
hslider(450, 514, 150, "horizontalSlider.pcx", 0, 50, transf_amt);


...should I do this instead?:
Code:
var value = 1;

hslider(450, 514, 150, "horizontalSlider.pcx", 0, 1, (value * transf_amt));


Keep in mind that transf_amt is the maximum value that I want the horizontal slider to have at run time. The variable "transf_amt" equals the maximum quantity of one particular type of item that the player is capable of transferring from one inventory bag to another at any given time.
Posted By: sivan

Re: hslider max value? - 08/14/14 09:31

no. you need pan_setslider().

put something like this is a while loop after panel creation (you don't need pointers as in the example i.e. you can ignore the *-s and use only simple var variables)

Code:
// fog limits update
   		if (*sky_fogend>*sky_camclipfar)
   			{
   				*sky_fogend = *sky_camclipfar;
   			}
   		if (*sky_fogstart>*sky_fogend)
   			{
   				*sky_fogstart = *sky_fogend;
   			}
   		pan_setslider(sky_lowpanel, 10,	100+22,365+2,	horiz_slider_bmp,slider_knob_bmp,	0,*sky_fogend,			*sky_fogstart);
   		pan_setslider(sky_lowpanel, 11,	100+22,385+2,	horiz_slider_bmp,slider_knob_bmp,	*sky_fogstart,*sky_camclipfar,	*sky_fogend);

Posted By: Ruben

Re: hslider max value? - 08/20/14 10:12

So, here is what I am trying to do. It seems like it would be simple, but I keep getting an error:

Code:
...

var max_quant_entFrom;

...

PANEL* invTransferAmount =
{
	layer = 1;
	
	digits (590, 490, 5, *, 1, transf_amt);
	button(640, 510, "transfer_button_click.pcx", "transfer_button.pcx", "transfer_button_hover.pcx",
	       buttonTransferItems, NULL, NULL);
	hslider(450, 514, 150, "horizontalSlider.pcx", 0, max_quant_entFrom, transf_amt);
}


I am trying to make the hslider max value be dynamic, to always equal the current value of max_quant_entFrom . However, I am getting this error:

Code:
Compiling PROGRAM.C - [Esc] to abort......................................
< hslider(450,514,150, "horizontalSlider.pcx", 0, max_quant_entFrom, transf_am>
PROGRAM.C 7:6 (): Number syntax max_quant_entFrom
.. 1.695 sec.
1 runtime errors
Error E355: Startup failure - any key to abort



If I change the "max_quant_entFrom" value to a number like 50, then I get no errors, except that the max value is static at 50, instead of being dynamic to always equal "max_quant_entFrom". I know that max_quant_entFrom has a value, but it is not allowing the hslider to go error free in trying to use it.

Does anyone know what I am doing wrong to always get this error when I use "max_quant_entFrom" as the max value in hslider?
Posted By: txesmi

Re: hslider max value? - 08/21/14 08:15

Hi Ruben,
it is not possible to use variables as limits on sliders. You can define the limits of the slider with the content of a variable but no with the variable itself as you tried. You get that error when trying to define a limit with the content of a non initialized variable.

You only need to modify the slider just before showing the panel. 'pan_setslider' works a bit different, parallel to 'slider' instead of 'hslider'. Here is an example:

Code:
var transf_amt = 0;

BMAP *bmpTransferOn = "transfer_button_click.pcx";
BMAP *bmpTransferOff = "transfer_button.pcx";
BMAP *bmpTransferOver = "transfer_button_hover.pcx";
BMAP *bmpTransferSliderBg = "horizontalSliderBg.pcx";
BMAP *bmpTransferSliderKnob = "horizontalSlider.pcx";

function buttonTransferItems ( var button_id, PANEL *panel )
{
	reset ( panel, SHOW );
	printf ( "%.0f", (double)transf_amt );
}

PANEL* invTransferAmount =
{
	digits  ( 590, 490, 5, *, 1, transf_amt );
	button  ( 640, 510, bmpTransferOn, bmpTransferOff, bmpTransferOver, buttonTransferItems, NULL, NULL );
	slider ( 450, 514, bmpTransferSliderBg, bmpTransferSliderKnob, 0, 1, transf_amt );
	flags = OUTLINE;
}

...
transf_amt = 0;
var count_max = 1 + floor ( random(10) ); // maximum of items
pan_setslider ( invTransferAmount, 1, 450, 514, bmpTransferSliderBg, bmpTransferSliderKnob, 0, count_max, transf_amt );
set ( invTransferAmount, SHOW );
...



Salud!
Posted By: Ruben

Re: hslider max value? - 09/23/14 10:05

I apologize for not responding sooner txesmi. At the time I started this task, I realized that I needed to accomplish another task before starting this task, and I am still working on that former task, although it may be almost finished.

In either case, I wanted to say thank you for your help in your last comment to this post. I will be looking at it once I am done with the previous task. Thanks again.
Posted By: Ruben

Re: hslider max value? - 12/20/14 07:18

Tsexmi: I tried your solution. It does set transf_amt as the max value on the hslider. However, it does not allot equal increments for the max value on the slider bar. For example, when I set my hslider as such:

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



...the amount on the hslider will start off at the transf_amt toward the far right of the horizontal slider (example: transf_amt = 4 ). However, when I move the slider button to the left, it immediately places the transf_amt value in the range of 0 - 1, and it does not go any higher than 1. I am really trying to make the horizontal slider dynamic in that transf_amt needs to be the max value any time this horizontal slider is accessed, and if I move the horizontal button to the left, it should increment one less than what transf_amt equals, and keep incrementing one less as I keep moving the horizontal button to the left, all the way down to 0 , in equal increments.

Any idea on what I am doing wrong?
Posted By: Ruben

Re: hslider max value? - 12/29/14 06:38

Originally Posted By: txesmi
Hi Ruben,
it is not possible to use variables as limits on sliders. You can define the limits of the slider with the content of a variable but no with the variable itself as you tried. You get that error when trying to define a limit with the content of a non initialized variable.

You only need to modify the slider just before showing the panel. 'pan_setslider' works a bit different, parallel to 'slider' instead of 'hslider'. Here is an example:

Code:
var transf_amt = 0;

BMAP *bmpTransferOn = "transfer_button_click.pcx";
BMAP *bmpTransferOff = "transfer_button.pcx";
BMAP *bmpTransferOver = "transfer_button_hover.pcx";
BMAP *bmpTransferSliderBg = "horizontalSliderBg.pcx";
BMAP *bmpTransferSliderKnob = "horizontalSlider.pcx";

function buttonTransferItems ( var button_id, PANEL *panel )
{
	reset ( panel, SHOW );
	printf ( "%.0f", (double)transf_amt );
}

PANEL* invTransferAmount =
{
	digits  ( 590, 490, 5, *, 1, transf_amt );
	button  ( 640, 510, bmpTransferOn, bmpTransferOff, bmpTransferOver, buttonTransferItems, NULL, NULL );
	slider ( 450, 514, bmpTransferSliderBg, bmpTransferSliderKnob, 0, 1, transf_amt );
	flags = OUTLINE;
}

...
transf_amt = 0;
var count_max = 1 + floor ( random(10) ); // maximum of items
pan_setslider ( invTransferAmount, 1, 450, 514, bmpTransferSliderBg, bmpTransferSliderKnob, 0, count_max, transf_amt );
set ( invTransferAmount, SHOW );
...



Salud!

Thank you Txesmi! Due to your advice, I finally got the slider max value to work. Thanks again! :-)
Posted By: txesmi

Re: hslider max value? - 01/04/15 13:51

happy to help!
© 2024 lite-C Forums