Discuss Scratch

Falvax
Scratcher
7 posts

Operators

Hey I really need help with operators I don't know how to use operators if you could make a tutorial or tell me in the comment I would be so happy here are the things I don't know when do I use them which one do I use addition subtraction divide or multiplication and how do i combine them and when do I combine them thanks
codeywhizz
Scratcher
100+ posts

Operators

So you want to use urs operators how you do in the real world, like say you want to compute if u have 7 apples and ate 3 it would be
7+3
or if there are 5 boys with 4 cookies it is just
5*4
as multiplication is written as a *

Notice how these are all calculations you do in real life, except they are shown in block symbols.

When combining 2, it does not follow BODMAS or PEDMAS which you are taught it school but you have to tell what order to do it in. It will work from the inside out so…
4*3+2
would give 14 as the 4*3 which is 12 is on the inside, and then gets added to the 2

But:
4*3+2
will output 20 as the 3+2 is on the inside, which is 5, and then it multiplies to get 20

The operators are:
+ for addition
- for subtraction
* for multiplication
/ for division
% for modulo (you can ignore this for now if you dont know this)

Let me know if you have questions
Falvax
Scratcher
7 posts

Operators

Ok here is my question when do I combine them and which ones do I combine like subtraction and division etc?
codeywhizz
Scratcher
100+ posts

Operators

Falvax wrote:

Ok here is my question when do I combine them and which ones do I combine like subtraction and division etc?
For whatever task you want to combine them, there is no specific moment where I tell you to use them, you use them literally for calculating, its like a calculator, you only click the add button when u want to add 2 numbers
EpicGhoul993
Scratcher
1000+ posts

Operators

codeywhizz wrote:

When combining 2, it does not follow BODMAS or PEDMAS which you are taught it school but you have to tell what order to do it in.
Other way to think about this: All operator blocks (and just all blocks in general) also have (visible?) brackets around them. For each block, the bracket is its border.
For example:
1+2 = (1+2) = 1+2 =33*4-5 = (3*(4-5)) = 3*(-1) =-3pickrandomxposition+-20todayssince2000 calculate (x+(-20)) first, then (days in 2000), then pick a "random" number in that range

Falvax wrote:

when do I use them
Most projects require operator blocks to calculate variables! Generally just use them however you see fit.
For (yet another) example, here's a script I came up with to solve someone else's problem about number abbreviations. I recolored all blocks that are not operators (and also the purple blocks because this forum hates me /j) to grey for demonstration.
defineabbreviatenumbersetoutputtonumberifabsofnumber<1000thenstopthis scriptset-illionto0repeatuntilabsofnumber<1000:setoutputtooutput/1000change-illionby1setoutputtojoinfloorofoutput*100/100item-illionof-illion names

Powered by DjangoBB