Adventure Game Studio

AGS Support => Advanced Technical Forum => Topic started by: Rui 'Trovatore' Pires on Sun 15/01/2006 14:57:05

Title: Mathematical help / suggestion (SOLVED)
Post by: Rui 'Trovatore' Pires on Sun 15/01/2006 14:57:05
Well, I need some sort of help with my maths - I need to know if something is possible, and if so how. If not, I'd like to suggest something to make the whole matter obsolete.

I have a slider, see. And I have a listbox to go with it, see. So far so good. But I want the slider to behave like a windows slider. Well, with the following code I've managed to get it to work in the exactly opposite way:

sldVerbs.Max=lstVerbs.ItemCount-lstVerbs.RowCount;
sldVerbs.Value=lstVerbs.TopItem;


What happens is, when the top item of the listbox is, say, 0, the value of the slider is also 0. And it moves accordingly to it's LOWER position. ANd when it moves UP, the listbox moves DOWN.

I'd like to know if there's some sort of mathematical formula, barring endless "ifs" and "elses" of manual and inefficient labout, to make it so that, for instance, when the max. value for the slider is 1 (between 0 and 1), putting it to 1 equals the listbox's top item being 0; and when max. value is 5, also make it equal the listbox's top item 0; and when it's 0, make it the listbox's furthest possible down item.

This was probably not very informative. Sorry, I don't know how to put it. But if it's not possible, then I'd like to suggest something else which may show what I'd like to achieve.

Would it be possible to make it so that sliders, which default to lowest value to the left/down, also allowed for the lowest value being to the right/up?
Title: Re: Mathematical help / suggestion
Post by: monkey0506 on Sun 15/01/2006 15:22:44
Maybe if you did:

sldVerbs.Min = 0;
sldVerbs.Max = lstVerbs.ItemCount - 1;
sldVerbs.Value = lstVerbs.TopItem;


I'm presuming that you're using the ListBox.Scroll(Up/Down) functions to update the top item.  I think that the problem may have been that you were setting the Max value to the number of items minus the number of items shown.  For example, if you had 10 items, and 4 could be shown at once, you would only have access to items 0 - 6.  Unless I've just misunderstood what you've done.
Title: Re: Mathematical help / suggestion
Post by: Rui 'Trovatore' Pires on Sun 15/01/2006 15:43:12
Oh, no, that's exactly what I wanted. That way I have good control over it. With your way, when I get to the lower numbers the final rows in the listboxes will display just empty rows, which I didn't want. This way, if I have 10 items and can show four, I can only change the first 6, which guarantees the described situation won't occur.

EDIT - At any rate, the problem would have remained. The value "0" of the slider would still correspond to it's lower position, and to the first item in the listbox.
Title: Re: Mathematical help / suggestion
Post by: Ashen on Sun 15/01/2006 16:50:36
sldVerbs.Value=sldVerbs.Max - lstVerbs.TopItem;

Perhaps?
Title: Re: Mathematical help / suggestion
Post by: Rui 'Trovatore' Pires on Sun 15/01/2006 17:07:31
Well well well! I feel downright silly for not having thought of that, because it works great. And I'll feel even sillier for this next question, but I must:

What code should I use, then, to replace the one that I called when I clicked on the actual slider? It used to be: "lstVerbs.TopItem=sldVerbs.Value;", but that doesn't work anymore, naturally, and I don't see what I can do... see, in the other situation I scroll first and move the slider accordingly, and now I have to move the slider and scroll accordingly.
Title: Re: Mathematical help / suggestion
Post by: Ashen on Sun 15/01/2006 17:19:23
lstVerbs.TopItem=sldVerbs.Max - sldVerbs.Value;

I'm guessing a bit at how exactly you've got it working, but that works for me.
Title: Re: Mathematical help / suggestion
Post by: Rui 'Trovatore' Pires on Sun 15/01/2006 17:21:58
What a beauty! Thank you very much for your help.