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: Scrollbar - Button Code Question  (Read 4595 times)

0 Members and 1 Guest are viewing this topic.

CMK2901

  • Lurker
  • *
  • Karma: 1
  • Offline Offline
  • Gender: Male
  • Posts: 35
  • Zoidberg is afoot!
    • View Profile
    • CMK Studios
Scrollbar - Button Code Question
« on: February 16, 2007, 01:34:37 AM »

So, I'm trying to implement a scroll bar for volume controls.  I used McCoy's example to create what I think is workable, but I'm having trouble understanding where to put the code to have it execute.

This may be completely wrong, but I've created a script in my OptionsDialog folder called MusicSlider.script.  In the definition file for the options GUI, I have:

Code: [Select]
BUTTON
  {
    NAME = "MusicSlider"
IMAGE = "interface\OptionsDialog\scrollTicker_n.png"
IMAGE_HOVER = "interface\OptionsDialog\scrollTicker_h.png"
IMAGE_PRESS = "interface\OptionsDialog\scrollTicker_h.png"
SCRIPT = "interface\OptionsDialog\MusicSlider.script"
X = 252
Y = 93
PARENT_NOTIFY = TRUE;
  }

in MusicSlider.script, I have my code.  The problem I'm having is that the initial code (outside all "on" statements) executes fine, and the code in "on LeftRelease" works fine, but any code I have in on "LeftClick" just doesn't seem to run; when I click on the button, it doesn't move (or perform anything I have in the event), but when I release the button, it does. 

Do I just have the code in the wrong place, or am I missing something?

Logged
CMK Studios
I don't think we're hearing the same voices.

metamorphium

  • Global Moderator
  • Addicted to WME forum
  • *
  • Karma: 12
  • Offline Offline
  • Gender: Male
  • Posts: 1511
  • Vampires!
    • View Profile
    • CBE  software s.r.o.
Re: Scrollbar - Button Code Question
« Reply #1 on: February 16, 2007, 08:36:44 AM »

try on "MusicSlider" instead of on "LeftClick"
Logged
J.U.L.I.A. Enhanced Edition, Vampires!, J.U.L.I.A., J.U.L.I.A. Untold, Ghost in the Sheet

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: Scrollbar - Button Code Question
« Reply #2 on: February 16, 2007, 09:15:09 AM »

Try removing the PARENT_NOTIFY line, so that the button only handles clicks and not the press event.
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

CMK2901

  • Lurker
  • *
  • Karma: 1
  • Offline Offline
  • Gender: Male
  • Posts: 35
  • Zoidberg is afoot!
    • View Profile
    • CMK Studios
Re: Scrollbar - Button Code Question
« Reply #3 on: February 18, 2007, 02:11:27 AM »

Thanks for the responses, but the problem is persisting.  I removed the PARENT_NOTIFY and I renamed the event "on MusicSlider", but there was no difference.  To be sure that it wasn't my code, I put the code I had in "MusicSlider" into "LeftRelease" and it definitely responds...not correctly, but the response is there.

I guess I'll leave my code, which is really McCoy's code for the most part:

Code: [Select]
#include "scripts\base.inc"


var sfxSlider; //just to hold some values
var MoveButton; //if true, the button updates its position with the mouse position

sfxSlider.DecimalVolume = (Game.GetGlobalSFXVolume() / 100); //get the sfx volume as a decimal for later (0 - 1)
sfxSlider.CurVolume = Game.GetGlobalSFXVolume(); //get the sfx volume for later (0 - 100)
sfxSlider.MaxXPos = 683; //screen position where slider is at maximum
sfxSlider.MinXPos = 252; //screen position where slider is at minimum

//set the slider's current position to a point on the slider bar that represents the current volume
self.X = sfxSlider.MinXPos + ((sfxSlider.MaxXPos - sfxSlider.MinXPos) * sfxSlider.DecimalVolume);

on "MusicSlider"
{
    var parent = self.Parent; //reference to the window that holds the button
    MoveButton = true; //the button must update it's position
    Game.MouseY = parent.Y + self.Y + (self.Height / 2); //place the cursor in the (vertical) middle of the volume button/ticker
    sfxSlider.MouseY = Game.MouseY; //update the mouse position info in the variable
Game.SetMousePos(0,0);

//play the test sound (it's good to hear something while you are increasing or decreasing the volume)
    Game.PlaySound("interface\system\sfx.ogg",true);

//loop that updates the mouse position and the volume value
    while (MoveButton)
    { 
  //This is needed because the button has relative coordinates (relative to the window) and the mouse
      // has absolute coordinates (relative to the screen).
      sfxSlider.AbsoluteX = parent.X + self.X; //the absolute Y in the screen of the button.
  sfxSlider.AbsoluteY = parent.Y + self.Y; //same for X
 
   //if the button is between the desired limits (in the slider area on the background image)
      if(self.X <= sfxSlider.MaxXPos && self.X >= sfxSlider.MinXPos)
      {
        sfxSlider.oldMouseX = sfxSlider.MouseX; //save the old mouse position to get the difference with the actual position later
        sfxSlider.MouseX = Game.MouseX;      //save the actual mouse position 

//get the difference between the old position and the actual positionand update the button pos. accordingly
        self.X = self.X + (sfxSlider.MouseX - sfxSlider.oldMouseX);
       
//same for the volume value                     
        sfxSlider.DecimalVolume = sfxSlider.DecimalVolume - (sfxSlider.MouseY - sfxSlider.oldMouseY);
      }
 
      if(self.X > sfxSlider.MaxXPos) //keep the mouse cursor and the button within limits (right limit)
      { 
        self.X = sfxSlider.MaxXPos;
        Game.MouseY = sfxSlider.oldMouseY;
        sfxSlider.MouseY = Game.MouseY;
        sfxSlider.DecimalVolume = 100;
      }
      if(self.X < sfxSlider.MinXPos) //same for the left limit
      {
        self.Y = sfxSlider.MinXPos;
        Game.MouseY = sfxSlider.oldMouseY;
        sfxSlider.MouseY = Game.MouseY;
        sfxSlider.DecimalVolume = 0;
      }

      //these two ifs keep the mouse cursor between the top and bottom sides of the button/slider
      if (Game.MouseY > sfxSlider.AbsoluteY + self.Height - 2)
  {
    Game.MouseY = sfxSlider.AbsoluteY + self.Height - 2;
  }
      if (Game.MouseY < sfxSlider.AbsoluteY + 2)
  {
    Game.MouseY = sfxSlider.AbsoluteX + 2;
      }
 
      if (Game.MouseY != sfxSlider.AbsoluteY + (self.Height / 2)) //and this one to keep it in the vertical middle
      {
        Game.MouseY = sfxSlider.AbsoluteY + (self.Height / 2);
        sfxSlider.MouseY = Game.MouseY;
      }   
      Game.SetGlobalSFXVolume(sfxSlider.CurVolume);
      Sleep(1); //yeah, maybe too short sleep time, but, hey, this one is the only script running,
    }
}

on "LeftRelease"
{   
  //when the mouse button is released, stop the sound and stop updating
  //the button position
  Game.StopSound();   
  MoveButton = false;
}

Any other possibilities?
Logged
CMK Studios
I don't think we're hearing the same voices.

metamorphium

  • Global Moderator
  • Addicted to WME forum
  • *
  • Karma: 12
  • Offline Offline
  • Gender: Male
  • Posts: 1511
  • Vampires!
    • View Profile
    • CBE  software s.r.o.
Re: Scrollbar - Button Code Question
« Reply #4 on: February 18, 2007, 09:36:16 AM »

ok, try putting Game.Msg("Clicked"); into the on "MusicSlider" to see if gets invoked. Maybe the code inside is invalid.
Logged
J.U.L.I.A. Enhanced Edition, Vampires!, J.U.L.I.A., J.U.L.I.A. Untold, Ghost in the Sheet

CMK2901

  • Lurker
  • *
  • Karma: 1
  • Offline Offline
  • Gender: Male
  • Posts: 35
  • Zoidberg is afoot!
    • View Profile
    • CMK Studios
Re: Scrollbar - Button Code Question
« Reply #5 on: February 19, 2007, 07:15:58 PM »

I put Game.Msg("Clicked"); in "LeftClick" and Game.Msg("Released"); in "LeftRelease"

When I click the button, nothing happens, and when I release, "Released" displays in the corner.  I put all my code from "LeftClick" into "LeftRelease" to see if the code itself worked, and it did when I released the mouse button.

So, it seems that "LeftClick" and "MusicSlider" are not being recognized by the engine as the events to go along with pressing the mouse button down, for whatever reason.  I'm at a loss, really.  :)

Any other ideas??
Logged
CMK Studios
I don't think we're hearing the same voices.

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: Scrollbar - Button Code Question
« Reply #6 on: February 19, 2007, 09:59:40 PM »

I'm kinda lazy to analyze McCoy's code now :) Here is the entire settings window from Five lethal demons. Hopefully you'll find it useful. Check especially the "thumb.script".
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

CMK2901

  • Lurker
  • *
  • Karma: 1
  • Offline Offline
  • Gender: Male
  • Posts: 35
  • Zoidberg is afoot!
    • View Profile
    • CMK Studios
Re: Scrollbar - Button Code Question
« Reply #7 on: February 20, 2007, 02:16:49 AM »

Alright, I discovered the problem...I'm feeling a little stupid right now, btw.  ;D

I had previously done some messing around with the "on LeftClick" function in game.script...it wasn't distributing certain mouse clicks correctly.  But I think I've fixed it and it seems to work now.

Thanks for the help, guys.
Logged
CMK Studios
I don't think we're hearing the same voices.
 

Page created in 0.039 seconds with 24 queries.