This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2008-01-23 11:34:57

Snowberry23
Scratcher
Registered: 2008-01-16
Posts: 5

Please help me with this?

Im making a new dress up game, not the boring usual kind either so...

I was just wondering how to make it so when you click a clothing item (click it once, not drag it) you can pick it up, when you click again, you put it down. and you can carry on picking it up and putting it down throughout the whole game.
There are many items and i only want each one to move if i click on that ONE.

=]

Offline

 

#2 2008-01-23 13:07:48

Paddle2See
Scratch Team
Registered: 2007-10-27
Posts: 1000+

Re: Please help me with this?

I've got a technique I've used that makes use of a variable called Selected that I define for each sprite (not for all sprites).  The code to pick up the sprite then looks like

When Sprite Clicked
Set Selected to 1 - Selected                    (this toggles the value between 1 and zero)
Wait 0.01 Seconds                                   (let things settle down a bit)
If Selected = 1
    Repeat Until Selected = 0
            Goto Mousepointer


If you want things to happen after the sprite is released from the mouse, you can put an ELSE branch on the IF statement and handle them there.  Good luck!


http://i39.tinypic.com/2nav6o7.gif

Offline

 

#3 2008-01-23 15:08:03

kevin_karplus
Scratcher
Registered: 2007-04-27
Posts: 1000+

Re: Please help me with this?

Snowberry23, it sounds like you want code like I used in my MasterMind game:
http://scratch.mit.edu/projects/kevin_karplus/12236

Try downloading that and looking at how the pegs are moved.

Offline

 

#4 2008-01-23 15:44:24

Snowberry23
Scratcher
Registered: 2008-01-16
Posts: 5

Re: Please help me with this?

Paddle2See wrote:

I've got a technique I've used that makes use of a variable called Selected that I define for each sprite (not for all sprites).  The code to pick up the sprite then looks like

When Sprite Clicked
Set Selected to 1 - Selected                    (this toggles the value between 1 and zero)
Wait 0.01 Seconds                                   (let things settle down a bit)
If Selected = 1
    Repeat Until Selected = 0
            Goto Mousepointer


If you want things to happen after the sprite is released from the mouse, you can put an ELSE branch on the IF statement and handle them there.  Good luck!

Thanks, that works for picking up the items, but i cant place them down on the character.

Offline

 

#5 2008-01-23 15:55:39

Paddle2See
Scratch Team
Registered: 2007-10-27
Posts: 1000+

Re: Please help me with this?

Hmmm, it works when I try it.  Can you upload the project so I can take a look at it?  You have to click again to put it down, but you probably already knew that.


http://i39.tinypic.com/2nav6o7.gif

Offline

 

#6 2008-01-23 16:04:45

Paddle2See
Scratch Team
Registered: 2007-10-27
Posts: 1000+

Re: Please help me with this?

Just realized that the code can be simplifed even further if you aren't doing anything special when you release the object.  You don't even need the IF statement.  It also looks like the Wait statement isn't really necessary.   The code is then just

When Sprite Clicked
Set Selected to 1 - Selected                    (this toggles the value between 1 and zero)
Repeat Until Selected = 0
            Goto Mousepointer

Of course if you want to make sure the object lines up perfectly with the person underneath, you might want to keep the IF and add some logic to reposition the object where it is supposed to go.  That gets a little more complicated.

Last edited by Paddle2See (2008-01-23 16:05:27)


http://i39.tinypic.com/2nav6o7.gif

Offline

 

#7 2008-01-23 16:28:56

Snowberry23
Scratcher
Registered: 2008-01-16
Posts: 5

Re: Please help me with this?

Paddle2See wrote:

Just realized that the code can be simplifed even further if you aren't doing anything special when you release the object.  You don't even need the IF statement.  It also looks like the Wait statement isn't really necessary.   The code is then just

When Sprite Clicked
Set Selected to 1 - Selected                    (this toggles the value between 1 and zero)
Repeat Until Selected = 0
            Goto Mousepointer

Of course if you want to make sure the object lines up perfectly with the person underneath, you might want to keep the IF and add some logic to reposition the object where it is supposed to go.  That gets a little more complicated.

How does "selected" change from 1 back to zero to the item doesnt move anymore?

Offline

 

#8 2008-01-23 19:17:59

Paddle2See
Scratch Team
Registered: 2007-10-27
Posts: 1000+

Re: Please help me with this?

When you click the mouse again (with the object dangling off of the mouse pointer), it generates another When Clicked event so the (Selected = 1 - Selected) equation results in Selected becoming zero.  This stops the Until loop and releases the object.  Maybe you don't have the

               set Selected = 1- Selected

coded correctly?

[kevin_karplus: fixed typo in set statement.]

Last edited by kevin_karplus (2008-01-23 19:57:27)


http://i39.tinypic.com/2nav6o7.gif

Offline

 

Board footer