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

#1 2013-02-03 06:30:41

Sonickyle
Scratcher
Registered: 2010-10-16
Posts: 100

Variable Multiple Checker

Is there a way to check if a Variable is a multiple of something? eg. 3


http://i1270.photobucket.com/albums/jj616/Sonickyle27/BannerV1.png
My Online Status on Scratch: http://blocks.scratchr.org/API.php?user=Sonickyle&action=onlineStatus

Offline

 

#2 2013-02-03 13:43:18

kayybee
Scratcher
Registered: 2009-12-07
Posts: 1000+

Re: Variable Multiple Checker

Yes, you can use the
() mod ()
block in Operators.

It returns the remainder when dividin the first number by the second, so a multiple of a number will return remainder 0.

<[(x) mod (3)] = [0]>
will return true if x is a multiple of 3
will return false if x is not a multiple of three.

Offline

 

#3 2013-02-04 02:01:53

Sonickyle
Scratcher
Registered: 2010-10-16
Posts: 100

Re: Variable Multiple Checker

kayybee wrote:

Yes, you can use the
() mod ()
block in Operators.

It returns the remainder when dividin the first number by the second, so a multiple of a number will return remainder 0.

<[(x) mod (3)] = [0]>
will return true if x is a multiple of 3
will return false if x is not a multiple of three.

Thanks so much!


http://i1270.photobucket.com/albums/jj616/Sonickyle27/BannerV1.png
My Online Status on Scratch: http://blocks.scratchr.org/API.php?user=Sonickyle&amp;action=onlineStatus

Offline

 

#4 2013-02-04 02:17:01

Sonickyle
Scratcher
Registered: 2010-10-16
Posts: 100

Re: Variable Multiple Checker

Does this work with Decimals? I can't get it working...

forever
if <((timer) mod (0.5)) = (0)>
...
Basicly, it doesn't fire when the timer gets at 0.5, 1.0, 1.5, etc.


http://i1270.photobucket.com/albums/jj616/Sonickyle27/BannerV1.png
My Online Status on Scratch: http://blocks.scratchr.org/API.php?user=Sonickyle&amp;action=onlineStatus

Offline

 

#5 2013-02-05 19:01:19

ErnieParke
Scratcher
Registered: 2010-12-03
Posts: 1000+

Re: Variable Multiple Checker

Sonickyle wrote:

Does this work with Decimals? I can't get it working...

forever
if <((timer) mod (0.5)) = (0)>
...
Basicly, it doesn't fire when the timer gets at 0.5, 1.0, 1.5, etc.

Well, it should. I'm not entirely sure what's going on, though I do have an idea developing.  In the meanwhile, you could try doing this:

forever
if <(((round ((10) * (timer))) / (10)) mod (0.5)) = (0)>//Multiple the 10's by 10 for greater accuracy.
...

I hope that this helps!


http://i46.tinypic.com/35ismmc.png

Offline

 

#6 2013-02-06 02:16:29

Sonickyle
Scratcher
Registered: 2010-10-16
Posts: 100

Re: Variable Multiple Checker

ErnieParke wrote:

Sonickyle wrote:

Does this work with Decimals? I can't get it working...

forever
if <((timer) mod (0.5)) = (0)>
...
Basicly, it doesn't fire when the timer gets at 0.5, 1.0, 1.5, etc.

Well, it should. I'm not entirely sure what's going on, though I do have an idea developing.  In the meanwhile, you could try doing this:

forever
if <(((round ((10) * (timer))) / (10)) mod (0.5)) = (0)>//Multiple the 10's by 10 for greater accuracy.
...

I hope that this helps!

I'll give it a shot. Thanks for the help!


http://i1270.photobucket.com/albums/jj616/Sonickyle27/BannerV1.png
My Online Status on Scratch: http://blocks.scratchr.org/API.php?user=Sonickyle&amp;action=onlineStatus

Offline

 

#7 2013-02-06 02:21:10

Sonickyle
Scratcher
Registered: 2010-10-16
Posts: 100

Re: Variable Multiple Checker

It works! Thank you kayybee and ErnieParke!

[ReqClose]


http://i1270.photobucket.com/albums/jj616/Sonickyle27/BannerV1.png
My Online Status on Scratch: http://blocks.scratchr.org/API.php?user=Sonickyle&amp;action=onlineStatus

Offline

 

Board footer