Discuss Scratch

bruh-moment6
Scratcher
20 posts

NEED HELP

I have been working on a game recently and I came across an issue that I have no idea how to solve. its a top down scroller and in the game, you can pick up items by clicking on them. the problem is that when two items are directly Infront of each other, they both get picked up. I only want the player to pick up one object at a time. I cant figure it out and if someone could please tell me a script to solve this it would be greatly appreciated! btw all the items are clones.

Last edited by bruh-moment6 (April 1, 2024 20:21:00)


when green flag clicked
say [I have crippling depression]
invalidaccess
Scratcher
68 posts

NEED HELP

bruh-moment6 wrote:

I have been working on a game recently and I came across an issue that I have no idea how to solve. its a top down scroller and in the game, you can pick up items by clicking on them. the problem is that when two items are directly Infront of each other, they both get picked up. I only want the player to pick up one object at a time. I cant figure it out and if someone could please tell me a script to solve this it would be greatly appreciated!
you're picking up by clicking them?
bruh-moment6
Scratcher
20 posts

NEED HELP

invalidaccess wrote:

bruh-moment6 wrote:

I have been working on a game recently and I came across an issue that I have no idea how to solve. its a top down scroller and in the game, you can pick up items by clicking on them. the problem is that when two items are directly Infront of each other, they both get picked up. I only want the player to pick up one object at a time. I cant figure it out and if someone could please tell me a script to solve this it would be greatly appreciated!
you're picking up by clicking them?
yeah

when green flag clicked
say [I have crippling depression]
bruh-moment6
Scratcher
20 posts

NEED HELP

I think I'm just gonna give up on the game and trash it.

when green flag clicked
say [I have crippling depression]
RokCoder
Scratcher
1000+ posts

NEED HELP

bruh-moment6 wrote:

I think I'm just gonna give up on the game and trash it.
Giving up so easily doesn't bode well for future tasks.

Share the project and I'm sure you'll get lots of simple solutions. I'm sure you can handle this with something along the lines of setting a pickUp variable to false at the beginning of each frame, setting it to true when something has been picked up and checking that it's false before allowing anything to be picked up.


Scratch dabbling for fun…

han614698
Scratcher
1000+ posts

NEED HELP

RokCoder wrote:

bruh-moment6 wrote:

I think I'm just gonna give up on the game and trash it.
Giving up so easily doesn't bode well for future tasks.

Share the project and I'm sure you'll get lots of simple solutions. I'm sure you can handle this with something along the lines of setting a pickUp variable to false at the beginning of each frame, setting it to true when something has been picked up and checking that it's false before allowing anything to be picked up.
Theoretically if they're using the ‘when sprite clicked’ hat block then that wouldn't work because the code would be running at the exact same frame.

<Scratch Wikian | Forum Helper | 6000+ Posts>

Credit to -gge for the icons in my signature | I condensed all this code into five lines using [p] tags, idk why




invalidaccess
Scratcher
68 posts

NEED HELP

RokCoder
Scratcher
1000+ posts

NEED HELP

han614698 wrote:

RokCoder wrote:

bruh-moment6 wrote:

I think I'm just gonna give up on the game and trash it.
Giving up so easily doesn't bode well for future tasks.

Share the project and I'm sure you'll get lots of simple solutions. I'm sure you can handle this with something along the lines of setting a pickUp variable to false at the beginning of each frame, setting it to true when something has been picked up and checking that it's false before allowing anything to be picked up.
Theoretically if they're using the ‘when sprite clicked’ hat block then that wouldn't work because the code would be running at the exact same frame.
If they were using the click events then they wouldn't be having the problem - only the top sprite would be responding to the event…


Scratch dabbling for fun…

bruh-moment6
Scratcher
20 posts

NEED HELP

the sprites that I am trying to pick up are clones of the same sprite. its also not a dragging system. I click on the object, and it teleports into my hand. also, I'm using a script that says <if touching mouse, wait until mouse down>

when green flag clicked
say [I have crippling depression]
RokCoder
Scratcher
1000+ posts

NEED HELP

bruh-moment6 wrote:

the sprites that I am trying to pick up are clones of the same sprite. its also not a dragging system. I click on the object, and it teleports into my hand. also, I'm using a script that says <if touching mouse, wait until mouse down>
The method I suggested will work for this. You're not going to get anything more specific unless you share the project.


Scratch dabbling for fun…

bruh-moment6
Scratcher
20 posts

NEED HELP

RokCoder wrote:

bruh-moment6 wrote:

the sprites that I am trying to pick up are clones of the same sprite. its also not a dragging system. I click on the object, and it teleports into my hand. also, I'm using a script that says <if touching mouse, wait until mouse down>
The method I suggested will work for this. You're not going to get anything more specific unless you share the project.
k I will share it: https://scratch.mit.edu/projects/993013454

when green flag clicked
say [I have crippling depression]
bruh-moment6
Scratcher
20 posts

NEED HELP

holy * I solved it

when green flag clicked
say [I have crippling depression]
bruh-moment6
Scratcher
20 posts

NEED HELP

I SOLVED IT

when green flag clicked
say [I have crippling depression]
RokCoder
Scratcher
1000+ posts

NEED HELP

bruh-moment6 wrote:

I SOLVED IT
Looks like you solved it using advice given in this thread. Well done


Scratch dabbling for fun…

SUPERSONIC_racing
Scratcher
7 posts

NEED HELP

i need help making a sonic game
deck26
Scratcher
1000+ posts

NEED HELP

SUPERSONIC_racing wrote:

i need help making a sonic game
You need help learning to create your own new topic instead of posting on someone else's topic. Look for the New Topic button.
SUPERSONIC_racing
Scratcher
7 posts

NEED HELP

deck26 wrote:

SUPERSONIC_racing wrote:

i need help making a sonic game
You need help learning to create your own new topic instead of posting on someone else's topic. Look for the New Topic button.
thx for advice!

Powered by DjangoBB