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

#1 2012-03-14 17:05:31

turkey3
Scratcher
Registered: 2011-12-04
Posts: 500+

How to make an object do either

How do you make an object do either of something. For example, when flag clicked, do either move 10 steps or glide to x 0 y 0. If this is impossible then I guess it is a suggestion. If it is a suggetion, tell me If you support.

Last edited by turkey3 (2012-03-14 17:07:11)

Offline

 

#2 2012-03-14 17:55:35

MaxFlyboy
Scratcher
Registered: 2011-11-07
Posts: 100+

Re: How to make an object do either

It's possible, there are a few ways to do it.

You will need a variable dedicated just to this

when gf clicked
set [variable v] to <pick random [1] to [2]>
if <<variable>=[1]>
move (10) steps
end
if <<variable>=[2]>
glide to x:(0)y:(0)
end
You can also use a list for this

Last edited by MaxFlyboy (2012-03-14 17:56:23)


http://cdn.voodoofilm.org/images/upload/thumb/viral-video-2011.jpg click the picture for an AMV

Offline

 

#3 2012-03-14 18:02:00

bobbybee
Scratcher
Registered: 2009-10-18
Posts: 1000+

Re: How to make an object do either

An even more efficient way:

when gf clicked
if <(pick random [1] to [2]) = [1]>
move [10] steps
else
glide to x: [0] y: [0]
end


I support the Free Software Foundation. Protect our digital rights!

Offline

 

#4 2012-03-14 18:05:13

MaxFlyboy
Scratcher
Registered: 2011-11-07
Posts: 100+

Re: How to make an object do either

bobbybee wrote:

An even more efficient way:

when gf clicked
if <(pick random [1] to [2]) = [1]>
move [10] steps
else
glide to x: [0] y: [0]
end

Yes that also works, but I usually try to stay away from the if else blocks


http://cdn.voodoofilm.org/images/upload/thumb/viral-video-2011.jpg click the picture for an AMV

Offline

 

#5 2012-03-14 18:06:23

bobbybee
Scratcher
Registered: 2009-10-18
Posts: 1000+

Re: How to make an object do either

MaxFlyboy wrote:

bobbybee wrote:

An even more efficient way:

when gf clicked
if <(pick random [1] to [2]) = [1]>
move [10] steps
else
glide to x: [0] y: [0]
end

Yes that also works, but I usually try to stay away from the if else blocks

Why, though? Chaining if-else blocks is often helpful (if there were many conditions)


I support the Free Software Foundation. Protect our digital rights!

Offline

 

#6 2012-03-14 18:09:59

MaxFlyboy
Scratcher
Registered: 2011-11-07
Posts: 100+

Re: How to make an object do either

I am one of those Scratchers who use scratch as a starting point for harder programs, in fact I'm probably going to leave in a month or two


http://cdn.voodoofilm.org/images/upload/thumb/viral-video-2011.jpg click the picture for an AMV

Offline

 

#7 2012-03-15 10:00:57

scimonster
Community Moderator
Registered: 2010-06-13
Posts: 1000+

Re: How to make an object do either

MaxFlyboy wrote:

I am one of those Scratchers who use scratch as a starting point for harder programs, in fact I'm probably going to leave in a month or two

Most programs have if/else functions.
And I think that method was best.

Offline

 

Board footer