Quote: "Ok I tried this and it works but then when I scroll up to 0 I can not longer scroll."
That is to be expected.
I wrote that code to match the specification that you asked for - to stop it scrolling when it reaches zero.
I could rewrite it to match your new request but if I keep writing code every time you want the slightest change then you are not going to learn anything, and I would be the one to have written your game.
I'm still happy to help though, so I'll talk you through why it doesn't move after getting to zero and suggest some ways to change that.
So firstly, why does it no longer move when it gets to zero?
Let's assume that the uppermost text object (
level_select_text[0]) has a Y position of 4. When it gets to this line:
if GetRawMouseWheel()<>0 and GetTextY(level_select_text[0]) > 0
We ask: Has the wheel moved in any direction (
this is important later) and is the text object
level_select_text[0] 's Y position greater than zero?
Yes to both, so we continue and loop through all text objects updating their Y position.
Now, lets assume that the wheel has moved enough to move the text objects 5 units up. The next time through the loop text object
level_select_text[0] 's Y position is -1. So when we get to this line again:
if GetRawMouseWheel()<>0 and GetTextY(level_select_text[0]) > 0
Has the mouse wheel moved?
Yes
Is text object
level_select_text[0] 's Y position greater than zero?
No
So we skip the loop and don't update the position of any text object.
That's why it behaves the way it does. So how to fix that so that it is still able to move down?
At the moment you are checking to see if the mouse wheel has moved with no care about which direction it has moved.
A simple solution would be to ensure that the loop to move the text objects only occurs if the text object
level_select_text[0] 's Y position is greater than zero
and the mouse wheel has scrolled
upwards.
Once you have that, you can see it's a very small step to also stop scrolling in the other direction when some maximum value is reached.
One final thing to mention:
You are checking and moving the text based on
GetRawMouseWheel() So if you move the mouse wheel one click, it's value will change and remain changed, moving the text objects up every frame.
Instead you should be using
GetRawMouseWheelDelta() which only returns the amount the mouse wheel has moved since the last frame. The value will be very small and you will probably need to multiply it by some value to move your text.