Gamestudio Links
Zorro Links
Newest Posts
Blobsculptor tools and objects download here
by NeoDumont. 03/28/24 03:01
Issue with Multi-Core WFO Training
by aliswee. 03/24/24 20:20
Why Zorro supports up to 72 cores?
by Edgar_Herrera. 03/23/24 21:41
Zorro Trader GPT
by TipmyPip. 03/06/24 09:27
VSCode instead of SED
by 3run. 03/01/24 19:06
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (AndrewAMD, Imhotep), 567 guests, and 4 spiders.
Key: Admin, Global Mod, Mod
Newest Members
sakolin, rajesh7827, juergen_wue, NITRO_FOREVER, jack0roses
19043 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 2 1 2
hslider max value? #444478
08/12/14 07:57
08/12/14 07:57
Joined: Jun 2010
Posts: 590
California
Ruben Offline OP
User
Ruben  Offline OP
User

Joined: Jun 2010
Posts: 590
California
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?

Re: hslider max value? [Re: Ruben] #444481
08/12/14 10:53
08/12/14 10:53
Joined: Nov 2007
Posts: 2,568
Germany, BW, Stuttgart
MasterQ32 Offline
Expert
MasterQ32  Offline
Expert

Joined: Nov 2007
Posts: 2,568
Germany, BW, Stuttgart
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);


Visit my site: www.masterq32.de
Re: hslider max value? [Re: MasterQ32] #444482
08/12/14 12:08
08/12/14 12:08
Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
txesmi Offline
Serious User
txesmi  Offline
Serious User

Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
or use 'pan_setslider' to modify the constants of the slider.

Re: hslider max value? [Re: MasterQ32] #444511
08/13/14 06:10
08/13/14 06:10
Joined: Jun 2010
Posts: 590
California
Ruben Offline OP
User
Ruben  Offline OP
User

Joined: Jun 2010
Posts: 590
California
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); 

...



???

Last edited by Ruben; 08/13/14 06:12.
Re: hslider max value? [Re: Ruben] #444514
08/13/14 11:06
08/13/14 11:06
Joined: Mar 2011
Posts: 3,150
Budapest
sivan Offline
Expert
sivan  Offline
Expert

Joined: Mar 2011
Posts: 3,150
Budapest
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);



Free world editor for 3D Gamestudio: MapBuilder Editor
Re: hslider max value? [Re: sivan] #444558
08/14/14 08:13
08/14/14 08:13
Joined: Jun 2010
Posts: 590
California
Ruben Offline OP
User
Ruben  Offline OP
User

Joined: Jun 2010
Posts: 590
California
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.

Re: hslider max value? [Re: Ruben] #444565
08/14/14 09:31
08/14/14 09:31
Joined: Mar 2011
Posts: 3,150
Budapest
sivan Offline
Expert
sivan  Offline
Expert

Joined: Mar 2011
Posts: 3,150
Budapest
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);



Free world editor for 3D Gamestudio: MapBuilder Editor
Re: hslider max value? [Re: sivan] #444865
08/20/14 10:12
08/20/14 10:12
Joined: Jun 2010
Posts: 590
California
Ruben Offline OP
User
Ruben  Offline OP
User

Joined: Jun 2010
Posts: 590
California
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?

Re: hslider max value? [Re: Ruben] #444894
08/21/14 08:15
08/21/14 08:15
Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
txesmi Offline
Serious User
txesmi  Offline
Serious User

Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
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!

Re: hslider max value? [Re: txesmi] #445753
09/23/14 10:05
09/23/14 10:05
Joined: Jun 2010
Posts: 590
California
Ruben Offline OP
User
Ruben  Offline OP
User

Joined: Jun 2010
Posts: 590
California
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.

Page 1 of 2 1 2

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1