• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Windows Code not working the way its intended

jameswillis

Member
Im new to game maker studio, and im trying to create a sliding menu for a project. I followed a tutorial on youtube to a T, and for some reason the slide bar doesnt work the way its supposed to. I did everything the guy in the video did, but for me, the slider goes only halfway down, and goes up beyond the slider bar. Can anyone tell me what im doing wrong?

Heres a link to the tutorial:



For obj_bar i used the following code:

LEFT PRESSED:
if (mouse_y < bottomLimit) && (mouse_y > topLimit)
{
a.y = mouse_y;
}

CREATE:
topLimit = y - (sprite_height/2) + (image_xscale*75);
bottomLimit = y + (sprite_height/2) - (image_xscale*75);

a = instance_create_layer(x, y, "Instances",obj_slider);
a.image_xscale = image_xscale;
a.image_yscale = image_yscale;
a.barLength = sprite_height;
a.topLimit = topLimit;
a.bottomLimit = bottomLimit;
a.y = topLimit;
a.depth = depth - 1;



For obj_slider i used the following code:

CREATE:
yy = 0;
grab = false;
percentage = 100;

LEFT PRESSED:
grab = true;

yy = y - mouse_y;

left released:
grab = false;

STEP:
if (!mouse_check_button(mb_left))
{
grab = false;
}

if (!grab)
{
exit;
}
else
{
if ((mouse_y + yy < bottomLimit) && (mouse_y + yy > topLimit))
{
y = mouse_y + yy;
}
else if (mouse_y + yy > bottomLimit)
{
y = bottomLimit;
}
else if (mouse_y + yy < topLimit)
{
y = topLimit;
}
}

percentage = round(((y-bottomLimit)/(topLimit-bottomLimit))*100);
 
Last edited:

chamaeleon

Member
Copy and paste code between [CODE] and [/CODE] tags is vastly superior to using screenshots. If the code works in the video but not in your project, 99.9% of the time you did not actually follow something to a T. Saying something goes only halfway down and can go higher than expected might make one think about a difference in sprite origins in the video and in your project.
 

jameswillis

Member
thanks for the reply. I changed the post to just include my code instead of screenshots. Ill watch the video again, but ive already gone through it 4 times over pausing almost every second and thats NOT an exageration lol.
 

chamaeleon

Member
Since you are using sprite related information, have you ensured both the video and you use the same origin for relevant sprites?
 

jameswillis

Member
That was literally the exact problem. It's all fixed now and working. I had no idea that would effect it, but in retrospect it makes perfect sense lol. Thank you so much you're a life saver
 
Top