Discuss Scratch

OtakuFurryAlphaGamer
Scratcher
3 posts

How to make draggable items snap back to where it was before being dragged

I'm creating an inventory system based off of “Don't Escape” and I'm having an issue. I want to be able to take and move around an item - and if the item isn't touching something it can combine with it goes back to where it was in the inventory. Does anyone know how to achieve this?
yadayadayadagoodbye
Scratcher
1000+ posts

How to make draggable items snap back to where it was before being dragged

Save the previous slot index/x and y value (depending on how you do slots) into a (or 2) variables, check when the sprite is released to see if its not touching anything, if not, put it back into the slot based on the index/x and y value which you previously saved.

Scratchers that I've cati-fied
MineTurte
Scratcher
500+ posts

How to make draggable items snap back to where it was before being dragged

yadayadayadagoodbye wrote:

Save the previous slot index/x and y value (depending on how you do slots) into a (or 2) variables, check when the sprite is released to see if its not touching anything, if not, put it back into the slot based on the index/x and y value which you previously saved.
Isn't there a way that's even more optimized though? Idk I kinda forgot but I'm pretty sure there is…


also I would be responding on @Juni-Bug but apparently new scratchers can't talk on the forum! hints why I am currently speed running getting scratcher

Last edited by MineTurte (March 21, 2024 17:47:43)


15+ (not revealing age) girl. Pronouns are she/her.
Host of The Pi Counsel. Comment in studio to join.

Front-end web developer & software programmer. I use JS, HTML, & CSS. Learning python3 right now.
Grammar fanatic as well

If I helped you out consider following Juni-Bug!


Select this + shift + down arrow = view rest of signature

This is JuniperActias. AKA Moth mommy.





Signature gradients here





If you found this secret; reply with ‘uwu’ with absolutely no context













yadayadayadagoodbye
Scratcher
1000+ posts

How to make draggable items snap back to where it was before being dragged

MineTurte wrote:

Isn't there a way that's even more optimized though? Idk I kinda forgot but I'm pretty sure there is…
I don't see how that is unoptimized, you're only saving 2 values into variables, thats an O(1) operation
and it only takes up O(1) memory as well

Last edited by yadayadayadagoodbye (March 21, 2024 17:52:19)


Scratchers that I've cati-fied
MineTurte
Scratcher
500+ posts

How to make draggable items snap back to where it was before being dragged

yadayadayadagoodbye wrote:

MineTurte wrote:

Isn't there a way that's even more optimized though? Idk I kinda forgot but I'm pretty sure there is…
I don't see how that is unoptimized, you're only saving 2 values into variables, thats an O(1) operation
and it only takes up O(1) memory as well
It is optimized but what I'm saying is I could've sworn I remember seeing a way to do that but even simpler, but idk lol. Maybe I'm thinking of something else?

15+ (not revealing age) girl. Pronouns are she/her.
Host of The Pi Counsel. Comment in studio to join.

Front-end web developer & software programmer. I use JS, HTML, & CSS. Learning python3 right now.
Grammar fanatic as well

If I helped you out consider following Juni-Bug!


Select this + shift + down arrow = view rest of signature

This is JuniperActias. AKA Moth mommy.





Signature gradients here





If you found this secret; reply with ‘uwu’ with absolutely no context













OtakuFurryAlphaGamer
Scratcher
3 posts

How to make draggable items snap back to where it was before being dragged

Save the previous slot index/x and y value (depending on how you do slots) into a (or 2) variables, check when the sprite is released to see if its not touching anything, if not, put it back into the slot based on the index/x and y value which you previously saved.

Could you be a litte more specific? Sorry, its really complicated. I partially followed a tutorial named “How to make an UPGRADED INVENTORY system in Scratch - Tutorial”, rest is stuff I added.

I've added and removed a bunch of things, but nothing works. Heres what I have so far: https://scratch.mit.edu/projects/984367892/
OtakuFurryAlphaGamer
Scratcher
3 posts

How to make draggable items snap back to where it was before being dragged

yadayadayadagoodbye wrote:

Save the previous slot index/x and y value (depending on how you do slots) into a (or 2) variables, check when the sprite is released to see if its not touching anything, if not, put it back into the slot based on the index/x and y value which you previously saved.

Hey, i've been trying a few things out but im still a little confused. It's hard since theres an animation for the inventory that plays.

Powered by DjangoBB