Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: migrator on Tue 22/11/2016 22:32:21

Title: Slider OnChange property **SOLVED**
Post by: migrator on Tue 22/11/2016 22:32:21
Hi! I'm wrote a custom save/load routine with screenshots. I use a slider to move it up and down but, now, I want to be able to use the mouse wheel too.

I wrote this little code to check the funcionality.

GUIControl *pgcOverGUIControl = GUIControl.GetAtScreenXY(mouse.x, mouse.y);
   //If there's a GUI control
   if (pgcOverGUIControl != null){
      //Check if a Slider
      Slider *pslSlider = pgcOverGUIControl.AsSlider;
      if (pslSlider != null){
         //If a Slider, Check if the mousewheel was used.
         if (button == eMouseWheelSouth){
            pslSlider.Value --;
         } else if (button == eMouseWheelNorth){
            pslSlider.Value ++;
         }
      }
   }

Now the Slider changes with the mousewheel, but that change don't runs the OnChange event of the Slider.

What I have to do to make the OnChange event of the Slider will be launched?

Thanks
Title: Re: Slider OnChange property
Post by: Crimson Wizard on Tue 22/11/2016 23:46:06
OnChange event is not triggered when you modify value in script, but you may call event handler yourself.
Since you get any slider from mouse position, you cannot call particular's slider handle right away, but firstly, you could use one handler for all sliders if that is convenient for you (since handler takes control pointer as parameter), or secondly, you may write a function that would choose what to do depending on which slider was modified, for example:
Code (ags) Select

function OnAnySliderChange(Slider *pslSlider)
{
   // do something to any slider
   // or find out which slider's handler to call
   if (pslSlider == sldSomeSlider)
      sldSomeSlider_OnChange(pslSlider);
   else if (pslSlider == sldAnotherSlider)
      sldAnotherSlider_OnChange(pslSlider);
   // and so on
}


<...>
if (button == eMouseWheelSouth){
   pslSlider.Value --;
   OnAnySliderChange(pslSlider);
} else if (button == eMouseWheelNorth){
   pslSlider.Value ++;
   OnAnySliderChange(pslSlider);
}

Title: Re: Slider OnChange property
Post by: migrator on Wed 23/11/2016 11:58:33
Thanks Crimson Wizard, it works fine.

And, this way, it's possible to optimize all the Sliders changes in only one function.