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

#1 2010-05-29 12:51:42

benjamin2
Scratcher
Registered: 2008-10-18
Posts: 1000+

Divisible By Block

I think I could really do with a block that only lets things do themselves if a certain number is divisible by another number.
Example:

When green flag clicked

set [variable] to (pick random 1 to 99)

if     ( (variable) is divisible by (3) )

       broadcast [Win]

else

       stop all



stop script

Where the (3) is you can place whatever number you like. In this case, if variable becomes divisible by 3 leaving no decimal, you win, if not, the game stops.

Examples:
If it becomes 34, the game stops.
If it becomes 63, you win.
If it becomes 25, the game stops.
If it becomes 6, you win.
If it becomes 94, the game stops.

So, could this block be added in 2.0?


http://i.imgur.com/gp6tZ.gif

Offline

 

#2 2010-05-29 12:55:06

coolstuff
Community Moderator
Registered: 2008-03-06
Posts: 1000+

Re: Divisible By Block

You can already do that using the ( ( ) mod ( ) ) block. It returns the remainder after dividing. For instance, 120 mod 10 is 0, because it divides evenly, while 120 mod 11 is 10, because 10 is remaining after dividing. Basically, if the two numbers divide evenly, it should return 0, which answers your suggestion.

Offline

 

#3 2010-05-29 12:56:25

meew0
Scratcher
Registered: 2010-02-22
Posts: 1000+

Re: Divisible By Block

You can do [blocks]<( (( x <mod> y )) <=> 0 )>[/blocks] instead of <x is divisible by y>.


http://i.imgur.com/mJV3j.pnghttp://i.imgur.com/HwWAX.pnghttp://i.imgur.com/sZ7Ui.pnghttp://i.imgur.com/0y6yh.pnghttp://i.imgur.com/nOC4l.png

Offline

 

#4 2010-05-30 04:10:07

helltank
Scratcher
Registered: 2010-05-21
Posts: 1000+

Re: Divisible By Block

What about like this:

When Green Flag Clicked
Pick a number from 1-99
If <number> mod [3]=0
Broadcast Win
else
Broadcast Lost


Error:Signature could not load. Please wait for an indefinite amount of time, until you realize you're gullible and go off to look for another potentially interesting signature to stare at.

Offline

 

Board footer