Please login or register.

Login with username, password and session length
Advanced search  

News:

IRC channel - server: waelisch.de  channel: #wme (read more)

Pages: [1] 2  All

Author Topic: Window button/static scripts  (Read 9765 times)

0 Members and 1 Guest are viewing this topic.

TheDerman

  • Regular poster
  • ***
  • Karma: 0
  • Offline Offline
  • Posts: 225
    • View Profile
Window button/static scripts
« on: November 15, 2007, 08:21:27 PM »

Hello,

I'm trying to make volume sliders in a window, and I'm wondering how to make a button or static control dragable?

The way I did it for a torn note puzzle was to have a loop on "LeftClick" which positioned the note pieces wherever the mouse cursor was, and then on "LeftRelease" locked them into a position.

I was thinking I would make my volume sliders in a similar way, but the difference is the torn note was in a scene, whereas my volume sliders are in a window.

So, can button or static controls have LeftClick and LeftRelease handlers somehow - maybe in their own scripts? I haven't come across this, as normally the window has a script, and it's just on "ButtonName" to do something, but I don't see how I could do what I want, with just that.

Thanks.
Logged

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: Window button/static scripts
« Reply #1 on: November 15, 2007, 08:29:35 PM »

So, can button or static controls have LeftClick and LeftRelease handlers somehow - maybe in their own scripts?
Yeah, buttons can. Static controls are not suitable, because they're not "clickable". Use buttons for sliders.
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

TheDerman

  • Regular poster
  • ***
  • Karma: 0
  • Offline Offline
  • Posts: 225
    • View Profile
Re: Window button/static scripts
« Reply #2 on: November 15, 2007, 08:45:22 PM »

Thanks.  8)

So, do I link the button to a script in the button definition, and then in that button script, put on "LeftClick" etc, as I would with a scene entity?
Logged

sychron

  • Wanderer zwischen den Welten
  • Global Moderator
  • Regular poster
  • *
  • Karma: 0
  • Offline Offline
  • Posts: 223
  • There is no spoon. The enemy gate is down!
    • View Profile
Re: Window button/static scripts
« Reply #3 on: November 15, 2007, 11:06:29 PM »

Define a variable to define wether you are dragging. Set it to true on LeftClick, and to false on LeftRelease. Then, add a handler for mouse movement which adjusts the button position when the dragging variable is set to true.
Logged
... delete the inner sleep ...

TheDerman

  • Regular poster
  • ***
  • Karma: 0
  • Offline Offline
  • Posts: 225
    • View Profile
Re: Window button/static scripts
« Reply #4 on: November 16, 2007, 12:12:39 AM »

Thanks.  8)

I can do the dragging bit though, as I don't see it being any different to how I dragged around the pieces of paper in my torn note puzzle. I'm just asking about linking scripts to buttons, and where the "LeftClick" etc goes in relation to a button, as I've never done that before. I've only done it with with scene entities, not window buttons.
Logged

sychron

  • Wanderer zwischen den Welten
  • Global Moderator
  • Regular poster
  • *
  • Karma: 0
  • Offline Offline
  • Posts: 223
  • There is no spoon. The enemy gate is down!
    • View Profile
Re: Window button/static scripts
« Reply #5 on: November 16, 2007, 12:44:46 AM »

Attach a script to the slider button and add handlers for LeftClick and LeftRelease. The release handler should also do the volume setting.
Logged
... delete the inner sleep ...

TheDerman

  • Regular poster
  • ***
  • Karma: 0
  • Offline Offline
  • Posts: 225
    • View Profile
Re: Window button/static scripts
« Reply #6 on: November 16, 2007, 04:09:31 AM »

Thanks. My sliders are now working perfectly.  8)

I actually set the volume in the loop that controls the slider, as I have a percentage display for the volume as well, which is updated as you move the slider back and forth.
Logged

maze

  • Occasional poster
  • **
  • Karma: 0
  • Offline Offline
  • Posts: 59
  • Good news
    • View Profile
Re: Window button/static scripts
« Reply #7 on: November 16, 2007, 08:00:05 AM »

Hi Derman,
just at the moment i'll need a slider too. It would be nice (and save my time), if you post your loop script.  ???
Thanks
« Last Edit: November 16, 2007, 08:34:32 AM by maze »
Logged

TheDerman

  • Regular poster
  • ***
  • Karma: 0
  • Offline Offline
  • Posts: 225
    • View Profile
Re: Window button/static scripts
« Reply #8 on: November 16, 2007, 04:05:17 PM »

here you go:

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.    while(IsDragging && Game.MouseX>516 && Game.MouseX<618)
  13.     {
  14.      this.X = Game.MouseX;
  15.          Game.SetGlobalMusicVolume(this.X-517);
  16.      Sleep(1);
  17.         }
  18.    Sleep(1);
  19.   }
  20. }
  21.  
  22. ////////////////////////////////////////////////////////////////////////////////
  23. on "LeftRelease"
  24. {
  25.  IsDragging = false;
  26. }
  27.  

This goes in the script for the music slider BUTTON. It creates a dragable area which is 100 pixels wide, which relates directly the the 0-100% range of the volume. You also need to put a LeftRelease handler on the actual window script and set IsDragging=false; in there so that releasing the left mouse button always stops the slider BUTTON dragging, no matter where you release the left mouse button.

Also, as with any script, it might not work perfectly for what you personally want to do.  8)
Logged

maze

  • Occasional poster
  • **
  • Karma: 0
  • Offline Offline
  • Posts: 59
  • Good news
    • View Profile
Re: Window button/static scripts
« Reply #9 on: November 18, 2007, 03:57:34 PM »

Sure, but it brought me on the right way.

Many thanks!
Logged

sychron

  • Wanderer zwischen den Welten
  • Global Moderator
  • Regular poster
  • *
  • Karma: 0
  • Offline Offline
  • Posts: 223
  • There is no spoon. The enemy gate is down!
    • View Profile
Re: Window button/static scripts
« Reply #10 on: November 18, 2007, 04:30:17 PM »

I would replace the inner while with an if and delete the inner sleep (sounds cool ...) -- or do you have to use while there for any special reason?
Logged
... delete the inner sleep ...

TheDerman

  • Regular poster
  • ***
  • Karma: 0
  • Offline Offline
  • Posts: 225
    • View Profile
Re: Window button/static scripts
« Reply #11 on: November 18, 2007, 09:47:01 PM »

Actually, maybe you are right.  8)

But anyway - it works fine - so I'll just leave it.

« Last Edit: November 18, 2007, 09:48:38 PM by TheDerman »
Logged

TheDerman

  • Regular poster
  • ***
  • Karma: 0
  • Offline Offline
  • Posts: 225
    • View Profile
Re: Window button/static scripts
« Reply #12 on: November 19, 2007, 05:20:28 AM »

Ok, I deleted the inner while and sleep (that DOES sound cool  8)), and it works the exact say way, so if anyone is interested:

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.  
Logged

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: Window button/static scripts
« Reply #13 on: November 19, 2007, 01:46:12 PM »

Much better.
I found an old slider.script on FTP, which does basically the same, but takes the window position into account.
http://dead-code.org/download/slider.script
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

rkitting

  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 44
    • View Profile
Re: Window button/static scripts
« Reply #14 on: July 07, 2008, 05:29:48 PM »

I have tried this and for some reason I never come into the "LeftRelease" Event and it keeps scrolling the button after releasing. Also the button doesn't stay under the mouse cursor. Anyone have a clue why this could be happening?
Logged
Pages: [1] 2  All
 

Page created in 0.164 seconds with 24 queries.