Slider code isn’t working

Hi! Thank you very much!

I am trying to create a slider to control the speed of an animation. I want to use the “Drag Me” custom rule with the rectangle shape, and I want the rectangle to be draggable only within a specific vertical range. Here’s what I have in the code for the rectangle:

When Self is Pressed
Check once if Self_y-position < 600 and Self_y-position > 200
Drag Me

The problem occurs when the slider gets dragged to the bottom or the top of the range. It stops working. I understand that at the bottom, the y-pos is now equal to 200 (or at the top, it’s equal to 600) and therefore the Check Once returns “false” and the Drag Me code won’t run.

I’ve tried a few things to get around this, none of which worked. Can anyone help me figure this out?

Thanks, and Happy Holidays!
ObedientNarwhal

7 Likes

The ‘Drag Me’ custom rule probably isn’t going to work for what you want.

Here’s a project I’ve made. See if you can work out how to put it in your own game! (Click the greenish-blue bit to view it.)

If this wasn’t what you wanted, feel free to explain more and I’ll try to help.


Also, you don’t need to sign off at the bottom of your posts. We can see your name at the top. :smile:

@ObedientNarwhal

6 Likes

Thanks! I’ll give it a try.

5 Likes

Thank you, @MISSION_IMPOSSIBLE, that looks like what I needed!

5 Likes

You’re welcome. :smile:
If you need any more, help just tag me.

4 Likes

I’d recommend duplicating the custom rule, changing the x position to self x position (stay at the same x) and then using the min and max math blocks with last touch y. It’d be something like
Set position x: self x position, y: min(600,max(200,last touch y))

5 Likes