Slider's script

You must understand the Game Editor concepts, before post here.

Slider's script

Postby Thanx » Sat Feb 02, 2008 2:25 pm

Hi everyone!
Lately I've started making a game, where you can have a number of players from 2-8. To keep the nice interface, I decided to make a slider which you can pull around. I didn't get too far... :D :( I just tried to make it stop at a point (the ends of the slides) when the mouse went too far. Somehow I didn't have success. I have a variable (slidemarkvar) which is set to 2 at the mouse-button-down event, and is set back to 1 at the mouse-button-up event. On the Draw event of that slider thingy I have the following code:
Code: Select all
if(slidemarkvar==2)
{
    FollowMouse("slidermark", X_AXIS);
    if(xmouse > 45)
    {
        slidermark.x=45;
    }
    if(xmouse < -130)
    {
        slidermark.x= -130;
    }
}


But here's the problem: When I hold the mouse button down, it stays in one place (somewhere around 40), when I release the mouse button, it follows the mouse on the x axis as it should, but it doesn't stop at 45 and -130! What's the problem? Can anyone help, please!
http://www.youtube.com/watch?v=XyXexDJBv58
http://www.youtube.com/watch?v=Be4__gww1xQ
These are me and playing the piano (second one with a friend/fellow student)
Hope you watch and enjoy!
User avatar
Thanx
 
Posts: 314
Joined: Sat Jan 26, 2008 10:07 pm
Location: Home sweet home! :)
Score: 24 Give a positive score

Re: Slider's script

Postby zygoth » Sat Feb 02, 2008 11:17 pm

Here is what I would do...

if(slidemarkvar == 2 && slidermark.x <= 45 && slidermark.x >= 130)FollowMouse("slidermark", X_AXIS);

I don't know if you have to tell it to stop following the mouse or not...if you do, just have it stop at the mouse button up event.

Hope this helps
Nova: 100% Vertigo/Mazeman: 100%
Visit my website to download them both! http://www.ketonegames.com
User avatar
zygoth
 
Posts: 140
Joined: Mon Jun 11, 2007 6:37 pm
Score: 5 Give a positive score

Re: Slider's script

Postby Thanx » Sun Feb 03, 2008 7:33 am

Hello again!
I've solved the problem, so I'm going to share the script:
The Mouse Button Down and Up events have not changed, but many changes in the OnDraw! :)
Code: Select all
if(slidemarkvar == 2)
{
    if(slidermark.x > 51)
    {
        slidermark.x = 51;
    }
    if(slidermark.x < -123)
    {
        slidermark.x = -123;
    }
 
 
    FollowMouse("slidermark", X_AXIS);
 
 
    if(x > -123 && x < -109)
    {
        slidermark.x = -123;
        choosen_number.textNumber = 2;
    }
    if(x > -108 && x < -80)
    {
        slidermark.x = -94;
        choosen_number.textNumber = 3;
    }
    if(x > -79 && x < -51)
    {
        slidermark.x = -65;
        choosen_number.textNumber = 4;
    }
    if(x > -50 && x < -22)
    {
        slidermark.x = -36;
        choosen_number.textNumber = 5;
    }
    if(x > -21 && x < 8)
    {
        slidermark.x = -7;
        choosen_number.textNumber = 6;
    }
    if(x > 7 && x < 37)
    {
        slidermark.x = 22;
        choosen_number.textNumber = 7;
    }
    if(x > 36 && x < 51)
    {
        slidermark.x = 51;
        choosen_number.textNumber = 8;
    }


}
if(slidemarkvar != 2)
{
       slidermark.x = slidermark.xprevious;
}


First if statement accures when the mouse-button is held down. It will follow the mouse, but if the marker wants to go too far, it will be set back to the end of the slider. The rest of the if statement tells the marker to go to specific places if within a small range of them, and then set the choosen number to the defined value, which is the choosen number of players.
But what happens if you release :?: Notice the last if statement in that code (below too):

Code: Select all
if(slidemarkvar != 2)
{
       slidermark.x = slidermark.xprevious;
}

This keeps the slider in place even when the mousebutton is released. (This if statement was which I was complicating SO much, when the answer was SO simple! :D )
http://www.youtube.com/watch?v=XyXexDJBv58
http://www.youtube.com/watch?v=Be4__gww1xQ
These are me and playing the piano (second one with a friend/fellow student)
Hope you watch and enjoy!
User avatar
Thanx
 
Posts: 314
Joined: Sat Jan 26, 2008 10:07 pm
Location: Home sweet home! :)
Score: 24 Give a positive score

Re: Slider's script

Postby DilloDude » Sun Feb 03, 2008 8:25 am

This can be done more simply:
Code: Select all
if (slidemarkvar == 2)
{
    int slidepos = xmouse - xscreen;
    if (slidepos > 51)
    {
        slidepos = 51;
    }
    else if (slidepos < -123)
    {
        slidepos = -123;
    }
    slidermark.x = slidepos;
}

Adjust the values used.
Also, it's more conventional (and more practical) to use 0 (false) and 1 (true) for a variable used as a boolean.
Image
User avatar
DilloDude
 
Posts: 866
Joined: Tue Jan 24, 2006 9:51 am
Location: Nyerellion
Score: 58 Give a positive score


Return to Advanced Topics

Who is online

Users browsing this forum: No registered users and 1 guest