Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Stapper on Thu 05/10/2017 04:31:30

Title: [SOLVED] Locking mouse movement to slider
Post by: Stapper on Thu 05/10/2017 04:31:30
Hi all,


I made a mini-game involving a slider that needs to be held at a certain value to complete it. It works great but currently you can exploit this by simply setting the cursor to the correct value and waiting it out.

Is it possible to prevent the player from setting the cursor? Or better yet, can I somehow tie the movement of the slider to the movement of the mouse (like moving the mouse up will move the slider at the same time)?


I hope that describes my problem clear enough...
Title: Re: Locking mouse movement to slider
Post by: eri0o on Thu 05/10/2017 05:13:50
You can just set your slider and make it's GUI not clickable.

Code (ags) Select

function repeatedly_execute(){
  if(GUI_With_Slider.Visible=true){
    slider.Value = (mouse.y*(slider.Max-slider.Min))/System.ViewportHeight;
  }
}


Could you show the code of what you have?


Title: Re: Locking mouse movement to slider
Post by: Stapper on Thu 05/10/2017 06:05:35
Wow that is quite the trick! Thanks a lot man!

It works well to control the slider, only it comes with two problems:
1. I cannot select the highest value, as my mouse doesn't seem to go all the way to the screen edge.
2. It moves in reverse. As my mouse goes lower, the number increases, thus making the slider go up.

Any way to fix these problems?

Oh and I used your code exactly like you mentioned:
Code (ags) Select
function room_RepExec()
{
  if (gSSD.Visible == true) {
    sldSSD.Value = (mouse.y*(sldSSD.Max-sldSSD.Min))/System.ViewportHeight;
  }
}
Title: Re: Locking mouse movement to slider
Post by: Khris on Thu 05/10/2017 09:13:27
It's a linear function: sldSSD.Value = m * mouse.y + t

I) sldSSD.Max = m * 0 + t
II) sldSSD.Min = m * (System.ViewportHeight - 1) + t

t = sldSSD.Max

sldSSD.Min - sldSSD.Max = m * (System.ViewportHeight - 1)
m = (sldSSD.Min - sldSSD.Max) / (System.ViewportHeight - 1)

function room_RepExec() {
  if (gSSD.Visible == true) {
    sldSSD.Value = mouse.y * (sldSSD.Min - sldSSD.Max) / (System.ViewportHeight - 1) + sldSSD.Max;
  }
}
Title: Re: Locking mouse movement to slider
Post by: Stapper on Thu 05/10/2017 23:43:30
OMG this works just perfectly!

Thanks a lot guys! :-D