Please login or register.

Login with username, password and session length
Advanced search  

News:

For WME related articles and tutorials visit WME Resource Center.

Author Topic: Slider problem  (Read 8136 times)

0 Members and 1 Guest are viewing this topic.

binary1

  • Supporter
  • Occasional poster
  • *
  • Karma: 0
  • Offline Offline
  • Posts: 51
    • View Profile
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? 
Logged

eborr

  • Regular poster
  • ***
  • Karma: 4
  • Offline Offline
  • Posts: 196
    • View Profile
Re: Slider problem
« Reply #1 on: June 02, 2015, 01:22:13 PM »

sorry for being dumb but which object does "this.X" refer to.

I have got slider code working in the past,  about 2 years, if I can find it I will post it 
Logged

binary1

  • Supporter
  • Occasional poster
  • *
  • Karma: 0
  • Offline Offline
  • Posts: 51
    • View Profile
Re: Slider problem
« Reply #2 on: June 02, 2015, 05:10:02 PM »

Thanks eborr!  I saw that you were working on a similar problem when I was searching the forum.

The user clicks on a computer console that brings up a window with the three slider bars.  The script is attached to the main window so I this should refer to the window that contains the slider bars.  I don't really need the parent part.  I had tried previously to attach a script to the slider but that resulted in the whole window moving around sometimes.  I have a number of variations by now but the one I posted seemed to be closest.  I read the material on windows in the online documentation and that was enough for all the menus that I have in the program but didn't have material that helped me with this.  Is there any other tutorial somewhere that I haven't found?
Logged

Dan Peach

  • Regular poster
  • ***
  • Karma: 4
  • Offline Offline
  • Posts: 100
    • View Profile
    • Viperante - Game Development
Re: Slider problem
« Reply #3 on: June 02, 2015, 09:23:56 PM »

I made working volume sliders before. :)

I don't really understand your problem though. And maybe it would help to know what you're trying to make happen, if not volume sliders. :)

binary1

  • Supporter
  • Occasional poster
  • *
  • Karma: 0
  • Offline Offline
  • Posts: 51
    • View Profile
Re: Slider problem
« Reply #4 on: June 03, 2015, 04:37:03 AM »

I have three scrollbars each with a button that is moved to the right increasing the value.  That part is similar to setting the volume control but instead of calling a method to play a sound file, after the three sliders are set, there will be a method to display an image.  It is actually a radiograph and the values are mA, kVp and time.  If the values are set too low, the displayed radiograph will be too light. If they are too high, the radiograph will be too dark.  There is another button to display a technique chart.  I'm having trouble getting the mouse cursor to drag the slider along the scroll bar.  Currently, I can drag the slider.  It temporarily "sticks" to the scrollbar but if I keep dragging, I can pull it off the bar.

Do you remember how you did the volume slider?

Thanks.
Logged

Dan Peach

  • Regular poster
  • ***
  • Karma: 4
  • Offline Offline
  • Posts: 100
    • View Profile
    • Viperante - Game Development
Re: Slider problem
« Reply #5 on: June 03, 2015, 09:59:04 AM »

I set a 100 pixel wide dragging area to correspond to the 100 percent of volume.

Code: WME Script
  1. #include "scripts\base.inc"
  2.  
  3. global IsDragging;
  4.  
  5. ////////////////////////////////////////////////////////////////////////////////
  6. on "LeftClick"
  7. {
  8.  IsDragging = true;
  9.  
  10.  while(IsDragging)
  11.   {
  12.    if(Game.MouseX>516 && Game.MouseX<618)
  13.     {
  14.      this.X = Game.MouseX;
  15.          Game.SetGlobalMusicVolume(this.X-517);
  16.         }
  17.    Sleep(1);
  18.   }
  19. }
  20.  
  21. ////////////////////////////////////////////////////////////////////////////////
  22. on "LeftRelease"
  23. {
  24.  IsDragging = false;
  25. }
  26.  

I attached this script to a window button, which was the thing you drag. So, in the loop, if mouseX is not between the values 517 and 617, then the button doesn't move. So, as soon as the button gets to the end or beginning of the slider bar, it stops. Worked fine for me. :)

binary1

  • Supporter
  • Occasional poster
  • *
  • Karma: 0
  • Offline Offline
  • Posts: 51
    • View Profile
Re: Slider problem
« Reply #6 on: June 03, 2015, 06:17:39 PM »

Thanks.  It works better but I'm still having problems.

The slider is now staying on the bar but it keeps dragging even when I release the mouse.  Also the game mouse is way off to the side and is actually off the window.

I tried putting the following in the code that calls the window:
   var tech = Game.LoadWindow("interface\slider\slider.window");
   tech.Center();
   tech.GoSystemExclusive();

That put the window in the bottom right corner.  Without tech.Center(), it was in the middle of the screen.

In the slider window, for the mASlider button, I have Parent Notify set to true and Focusable set to true.

Code: [Select]
global IsDragging = false;
//var IsDragging = false;

on "LeftClick"
{
IsDragging = true;
//PlaySounds();

while(IsDragging)
{
if(Game.MouseX > MinX  && Game.MouseX < MaxX)
{
Game.Msg("Game.MouseX is " + Game.MouseX);
Game.Msg("mASlider.X is " + mASlider.X);
this.X = Game.MouseX;;
//set variable here
//Game.SetGlobalMusicVolume
}
Sleep(1);
}
}


////////////////////////////////////////////////////////////////////////////////
on "LeftRelease"
{
IsDragging = false;
//StopSounds();
}


Any more suggestions?  I'm going to try starting over with another window.
Logged

binary1

  • Supporter
  • Occasional poster
  • *
  • Karma: 0
  • Offline Offline
  • Posts: 51
    • View Profile
Re: Slider problem
« Reply #7 on: June 04, 2015, 02:36:02 AM »

Still stuck.  I created a new window using the question template.  I added one horizontal slider bar and one slider button.  I cut and pasted the code from Dan Peach into a script and attached it to the slider button.  The only things I changed were the numbers for the beginning and end of the slider bar.  I have Parent Notify set to true and Focusable set to false.  When I click on the slider button, it only starts to move when the mouse is moved way to the left and it moves regardless of whether or not the mouse button is down.  It also doesn't matter what the y value of the mouse cursor is.  Once clicked, the slider moves left when the mouse is moved left and right when the mouse is moved to the right but the cursor isn't on the button. The slider is staying on the bar but the cursor is all over the screen, including off the window.

As a work around, I am moving the slider button using the arrow keys.  That works fine but I'd rather use the mouse if someone can tell me what I am doing wrong.

Thanks.
Logged

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: Slider problem
« Reply #8 on: June 04, 2015, 05:44:58 PM »

This is the settings window used in Helga: http://dead-code.org/download/slider.zip
If you copy it to your project, it should just work. You can use it as a starting point.
To fine-tune the sliders to your art, edit the thumb.script file and change the three values, MinX, MaxX and PointerOffset. These are the bounds of the slider (relative to window position) and the offset from the thumb's X position to mouse pointer.
I hope it helps.
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

Dan Peach

  • Regular poster
  • ***
  • Karma: 4
  • Offline Offline
  • Posts: 100
    • View Profile
    • Viperante - Game Development
Re: Slider problem
« Reply #9 on: June 05, 2015, 01:18:43 AM »

Ah yes, I think I had the problem that it still moved even after LeftRelease. It's because the "LeftRelease" is only on the actual button. I added the same "LeftRelease" code to the entire main window script. So, IsDragging=false is set no matter wherr you release. :)

binary1

  • Supporter
  • Occasional poster
  • *
  • Karma: 0
  • Offline Offline
  • Posts: 51
    • View Profile
Re: Slider problem
« Reply #10 on: June 05, 2015, 01:54:30 AM »

@Mnemonic:  Thank you so much!  That worked right out of the box. I'll start comparing the two codes to see where I went wrong.  The arrow keys worked ok but it is a lot more intuitive to click and drag.  It was a big problem for me because I need it for another window too.

@Dan Peach.  Thanks.  I'll make sure I put the LeftRelease in the right place.  I'm interested to see why my cursor is way off to the side.  That was the other problem I was having. 

I was at work all day but I'm back on it now.
Logged

binary1

  • Supporter
  • Occasional poster
  • *
  • Karma: 0
  • Offline Offline
  • Posts: 51
    • View Profile
Re: Slider problem
« Reply #11 on: June 05, 2015, 11:45:10 PM »

Everything is working great now!  I think the main problems were that I wasn't accounting for Parent.X and IsDragging was set incorrectly.  Thanks both of you!  That solved a major headache because I want to do something similar to display images elsewhere in the program.
Logged

Dan Peach

  • Regular poster
  • ***
  • Karma: 4
  • Offline Offline
  • Posts: 100
    • View Profile
    • Viperante - Game Development
Re: Slider problem
« Reply #12 on: June 07, 2015, 01:47:33 AM »

Awesome. Glad it works. :)
 

Page created in 0.024 seconds with 22 queries.