Discuss Scratch

Scratch739201
Scratcher
500+ posts

What does this script do?

What does this script do? Can please someone explain what this complex math means? (((round (mouse x)) / (30)) * (30))

( Sorry, I'm very bad in math. I would think that every one can have an idea when they see this except me D: )

(((round (mouse x)) / (30)) * (30))

Last edited by Scratch739201 (April 26, 2016 18:30:46)

deck26
Scratcher
1000+ posts

What does this script do?

The easiest way to see what it does is to work out a few examples but I suspect it should be

(round ((mouse x) / (30))) * (30)

If mouse-x is 25 the division gives approx 0.83 so rounding that gives 1 and multiplied by 30 it gives 30. If mouse-x is 50 the division gives 1.66 which rounds to 2 and multiplying gives 60.

We can easily see we're going to get a multiple of 30 each time so when does it change from 30 to 60? The answer is when the division gives 1.5 and 1.5 * 30 is 45 so any value more than 15 or less than 45 is converted to 30. Anything above 45 and less than 75 is converted to 60 and so on.

(You need to check what round does with 1.5 and 2.5 to know what it does for 45 and 75.)

So, if my change to the function was correct, it rounds the value to the nearest multiple of 30.
Scratch739201
Scratcher
500+ posts

What does this script do?

Do most users get to an idea using this math script? Why can't I? Am I bad in thinking if I don't have NOT A SINGLE idea what it could mean?

Last edited by Scratch739201 (April 26, 2016 18:45:54)

deck26
Scratcher
1000+ posts

What does this script do?

Scratch739201 wrote:

Do most users get to an idea using this math script? Why can't I? Am I bad in thinking if I don't have NOT A SINGLE idea what it could mean?
As I said though, work out a few examples and you should start to see a pattern. You don't even have to do it by hand - use two lists, one for input value and one for the output (it doesn't have to be mouse-x, you could create a list of input values and go through them one by one.

Breaking the function down into steps also helps but make sure you understand the order of calculation. What you showed and what I used are quite different - that may just be a problem getting Scratchblocks to show what you wanted.
deck26
Scratcher
1000+ posts

What does this script do?

… and remember I've been programming for nearly 40 years!
Scratch739201
Scratcher
500+ posts

What does this script do?

I'm bad in thinking that's problem. Do most users that are 5 months on Scratch know something like this or have an idea how it works?
Scratch739201
Scratcher
500+ posts

What does this script do?

deck26 wrote:

… and remember I've been programming for nearly 40 years!
Is there anything you don't know? I think you are 50 years old or something.
deck26
Scratcher
1000+ posts

What does this script do?

Scratch739201 wrote:

deck26 wrote:

… and remember I've been programming for nearly 40 years!
Is there anything you don't know? I think you are 50 years old or something.
Of course there are lots of things I don't know. No one knows everything! I know a reasonable amount about a lot of stuff and more about certain things but next to nothing about others - that's normal.

As for your question it depends on what you know before you spend 5 months learning Scratch, what age you are, how interested you are in certain things and so on. I'm not asking you these questions and don't want you to answer, just to realise that people learn things differently. You already presumably know more about Scratch than you thought you would a few months ago.

A willingness to learn and ask when you're unsure about something is a good start but sometimes it's also about the amount of effort you're willing to put in. There is nothing difficult about any of the component parts of the equation you asked about so it's the combination you're finding hard but the comments I've already made hopefully give you some guidance on how to approach this another time.
Scratch739201
Scratcher
500+ posts

What does this script do?

Why do I need to use (((round (mouse x)) / (30)) * (30)) and not this:

(round (mouse x))

?

Because “my number” times “something” divided by “something” will be the same result than “my number”.
deck26
Scratcher
1000+ posts

What does this script do?

Scratch739201 wrote:

Why do I need to use (((round (mouse x)) / (30)) * (30)) and not this:

(round (mouse x))

?

Because “my number” times “something” divided by “something” will be the same result than “my number”.
That ignores the ‘round’ though. If you don't do the rounding you are correct but in between the division and multiplication you've rounded the value. Otherwise 25 wouldn't change to 30, would it?
Scratch739201
Scratcher
500+ posts

What does this script do?

Why will 25 change to 30 is you use this script?
deck26
Scratcher
1000+ posts

What does this script do?

Scratch739201 wrote:

Why will 25 change to 30 is you use this script?
You're dividing the number by 30 first. 25 divided by 30, as I've already stated, is around 0.83.

What do you get if you round 0.83? You get 1. Multiply that by 30 and you get 30.

The order of the operations, as I said, is important. Dividing by 30 gives you the number of times that 30 goes into the number but when you round the result you get a whole number multiplied by 30.

If you can't see it perhaps you need to leave it for a few months and try again or discuss it with a teacher or something.

Scratch739201
Scratcher
500+ posts

What does this script do?

deck26 wrote:

Scratch739201 wrote:

Why will 25 change to 30 is you use this script?
discuss it with a teacher or something.
Why do you say teacher? Did you think I learn Scratch in school or something like that?
0xF3d04a
Scratcher
54 posts

What does this script do?

My guess is that you want the object to “snap” into a grid. Am I correct? If I am then this is what you want:
((round ((mouse x) * (30))) / (30))
But if you really want to use the script in the OP then it is pretty much the same as:
(round (mouse x))

Scratch739201 wrote:

Why will 25 change to 30 is you use this script?
It's because that's how rounding works. It rounds to the nearest number, if the number is 5 then the rounding process just got a bit interesting. If you are using ceiling then it will round up to the next largest set(tens, hundreds, etc.) However if you are using floor 5 rounds down to the lower set.

Last edited by 0xF3d04a (April 27, 2016 13:25:09)

Scratch739201
Scratcher
500+ posts

What does this script do?

Is it normally easy to understand for users that are 5 months or something? Plus, I don't understand why you need to use 30 to divide and multiply.
deck26
Scratcher
1000+ posts

What does this script do?

Scratch739201 wrote:

deck26 wrote:

Scratch739201 wrote:

Why will 25 change to 30 is you use this script?
discuss it with a teacher or something.
Why do you say teacher? Did you think I learn Scratch in school or something like that?
I was assuming you were still at school. My apologies if I'm wrong.

If you are at school speak to your Maths teacher - this isn't really a coding issue, it's maths.
Scratch739201
Scratcher
500+ posts

What does this script do?

I was assuming you were still at school. My apologies if I'm wrong.

Did you think I learned in school? Plus, do most users earn Scratch in school?
Scratch739201
Scratcher
500+ posts

What does this script do?

Also, I never had Scratch in school.
Scratch739201
Scratcher
500+ posts

What does this script do?

Why do you need to divide the number by 30? Can you explain a bit better with more information for me to read?
Scratch739201
Scratcher
500+ posts

What does this script do?

I watched a tutorial and looked at another forum question about grid snapping. And it helped me! The number “30” in my script is the size of the snapping grid!

But why and when I need to divide and multiply I still don't know. Please help.

Powered by DjangoBB