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

#1 2010-04-19 18:38:48

shadow_7283
Scratcher
Registered: 2007-11-07
Posts: 1000+

Int() function

Can anyone make an int() function for Scratch? Preferably, it would be part of the
( [abs^] of () ). I am really frustrated when I want to get rid of those decimals and have to create another variable and a few extra blocks of code to do it! THANKS!

Offline

 

#2 2010-04-19 18:57:19

ThePCKid
Scratcher
Registered: 2009-09-16
Posts: 1000+

Re: Int() function

Do you mean the floor function in mathematics?

Offline

 

#3 2010-04-19 20:31:54

AmoebaMan
Scratcher
Registered: 2009-01-26
Posts: 500+

Re: Int() function

that's what the command block (round ( )) block is for.  it's basically the mathematics "floor" function.


http://i942.photobucket.com/albums/ad269/RyanScathe/AmoebaMan.png

Offline

 

#4 2010-04-19 20:40:03

MathWizz
Scratcher
Registered: 2009-08-31
Posts: 1000+

Re: Int() function

Just use the round block. AND HAVE YOU SEEN http://scratch.mit.edu/projects/bharvey/995971????????????


http://block.site90.net/scratch.mit/text.php?size=30&text=%20A%20signature!&color=333333

Offline

 

#5 2010-04-19 20:50:35

ThePCKid
Scratcher
Registered: 2009-09-16
Posts: 1000+

Re: Int() function

The [block]<round( [/block] will work

Last edited by ThePCKid (2010-04-19 20:51:33)

Offline

 

#6 2010-04-19 21:25:02

climber59
Scratcher
Registered: 2009-12-15
Posts: 100+

Re: Int() function

I find it funny that four people all suggested the same block.


Check out my projects if you have a chance.

Offline

 

#7 2010-04-19 21:41:26

nXIII
Community Moderator
Registered: 2009-04-21
Posts: 1000+

Re: Int() function

Guys, round will not work. round(2.5) is 3, but int(2.5) is 2.
Here's a little lambda/function/whatever
int(x) = x - (x mod 1)

EDIT: I'm not sure about negative numbers, though.

Last edited by nXIII (2010-04-19 21:41:57)


nXIII

Offline

 

#8 2010-04-20 14:45:57

markyparky56
Scratcher
Registered: 2008-03-20
Posts: 1000+

Re: Int() function

What about something like this:
http://img402.imageshack.us/img402/3060/intscriptg.gif
Iv tested it, took me a while to work it out, but it works.

Last edited by markyparky56 (2010-04-20 14:47:32)


http://j.mp/jgVnTq
Check out my game engine development site: NewDawn I'm a Level 171 Scratcher.I am http://bit.ly/nkvLNT

Offline

 

#9 2010-04-20 18:54:31

shadow_7283
Scratcher
Registered: 2007-11-07
Posts: 1000+

Re: Int() function

That works, but there is a simpler way, and it is not convient.

As for everyone else, like nxIII explained, there is a difference between int() and round(). Int stands for integer, which basically takes away any decimal points.

Thanks nxIII, for the most helpful answer. I wish this was a block in Scratch though.

Offline

 

Board footer