16
Technical forum / Slider problem
« on: June 02, 2015, 07:22:22 AM »
I have three variables that I am trying to set with 3 horizontal slider bars similar to volume controls that have been discussed before. I have looked at the code given before by Fred and Mneumonic but can't quite get things to work. The cursor always seems to be off. There is a background called technique that holds the three sliding bars and there are three slider objects. I want the sliders to stay on the bars. The following is the closest I've managed:
#include "scripts\base.inc"
var MinX = 105;
var MaxX = 274;
var mA = 0;
var Parent = this.Parent;
kVpSlider = this.GetControl("kVpSlider");
mASlider = this.GetControl("mASlider");
timeSlider = this.GetControl("timeSlider");
technique = this.GetControl("technique");
////////////////////////////////////////////////////////////////////////////////
method SetValue(Percent)
{
mA = MinX + (MaxX - MinX) * (Percent / 100);
}
var IsDragging = false;
////////////////////////////////////////////////////////////////////////////////
on "LeftClick"
{
IsDragging = true;
PlaySounds();
while(IsDragging)
{
if(mASlider.X > MaxX) mASlider.X = MaxX;
else if(mASlider.X < MinX) mASlider.X = MinX;
else mASlider.X = Game.MouseX;
SetVolume((this.X - MinX) / (MaxX - MinX) * 100);
Sleep(1);
}
IsDragging = false;
}
////////////////////////////////////////////////////////////////////////////////
on "LeftRelease"
{
IsDragging = false;
//StopSounds();
}
on "close"
{
this.Close();
}
To start with, I am only trying with one of the sliders called mASlider but it doesn't stay completely within the margins of the slider bar. I've left some of the volume code in place right now but if I can get the slider working, I plan to change that.
Any suggestions? Has anyone done something similar?
#include "scripts\base.inc"
var MinX = 105;
var MaxX = 274;
var mA = 0;
var Parent = this.Parent;
kVpSlider = this.GetControl("kVpSlider");
mASlider = this.GetControl("mASlider");
timeSlider = this.GetControl("timeSlider");
technique = this.GetControl("technique");
////////////////////////////////////////////////////////////////////////////////
method SetValue(Percent)
{
mA = MinX + (MaxX - MinX) * (Percent / 100);
}
var IsDragging = false;
////////////////////////////////////////////////////////////////////////////////
on "LeftClick"
{
IsDragging = true;
PlaySounds();
while(IsDragging)
{
if(mASlider.X > MaxX) mASlider.X = MaxX;
else if(mASlider.X < MinX) mASlider.X = MinX;
else mASlider.X = Game.MouseX;
SetVolume((this.X - MinX) / (MaxX - MinX) * 100);
Sleep(1);
}
IsDragging = false;
}
////////////////////////////////////////////////////////////////////////////////
on "LeftRelease"
{
IsDragging = false;
//StopSounds();
}
on "close"
{
this.Close();
}
To start with, I am only trying with one of the sliders called mASlider but it doesn't stay completely within the margins of the slider bar. I've left some of the volume code in place right now but if I can get the slider working, I plan to change that.
Any suggestions? Has anyone done something similar?