Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Atelier on Sun 04/07/2010 18:10:01

Title: Sliders and Numbers [SOLVED]
Post by: Atelier on Sun 04/07/2010 18:10:01
Hi,

I have four sliders on a GUI (I'll call them A, B, C, D respectively).
I also have an int (MaxWorkforce, which can be anything depending on what the player's done beforehand).

What I need is to set the max values of ABCD according to MaxWorkforce. For example, if MaxWorkforce is say, 50:

If slider A's value is 50, BCD's max can only be 0.
If slider A's value is 20 and B's value is 10, CD's max can only be 20.
Edit: etc etc
If slider A's value is 0, ABCD's maxes are all 50.

Basically, I need to find a way so the player can "dish" out their workforce onto different jobs, while not exceeding their MaxWorkforce.
But how can I do this? Thanks.
Title: Re: Sliders and Numbers
Post by: ddq on Sun 04/07/2010 21:45:44
Check in each slider's OnChange function if A+B+C+D > 50. If so, set the current slider's value to 50 minus the sum of the values of the other three sliders.
Title: Re: Sliders and Numbers
Post by: Khris on Mon 05/07/2010 00:02:50
I'd do it differently:

In A's OnChange:

  float f = IntToFloat(MaxWorkForce - A) / IntToFloat(B + C + D);
  B = FloatToInt(f * IntToFloat(B));
  C = FloatToInt(f * IntToFloat(C));
  D = FloatToInt(f * IntToFloat(D));


Same for the three other sliders.

This will distribute the remainder among the other three sliders while keeping their proportions.
Title: Re: Sliders and Numbers
Post by: Atelier on Mon 05/07/2010 17:31:27
Heh, when the slider's value is set to 0, it points to the first line in your code Khris (the world implodes when dividing by 0 =D) I know this can't be helped, for now I've simply set their default value at 1. But is there some other way around this, so their min value can be 0?

Other than that, thanks again!
Title: Re: Sliders and Numbers
Post by: Khris on Mon 05/07/2010 17:58:38
Check if the sum is 0 first and if it is, skip the lines.

  int s = B + C + D;
  float f;
  if (s > 0) {
    f = IntToFloat(MaxWorkForce - A) / IntToFloat(s);
    B = FloatToInt(f * IntToFloat(B));
    C = FloatToInt(f * IntToFloat(C));
    D = FloatToInt(f * IntToFloat(D));
  }
Title: Re: Sliders and Numbers
Post by: Atelier on Tue 06/07/2010 15:45:24
Cool, thanks.