Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » Operators
- 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
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…
But:
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
((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
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
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 =3
((3) * ((4) - (5))) // = (3*(4-5)) = 3*(-1) =-3
(pick random ((x position) + (-20)) to (days since 2000)) // calculate (x+(-20)) first, then (days in 2000), then pick a "random" number in that range
when do I use themMost 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.
define abbreviate (number)
set [output v] to (number) ::grey
if <([abs v] of (number)) < [1000]> then {
stop [this script v] ::grey
} ::grey
set [-illion v] to (0) ::grey
repeat until <([abs v] of (number)) < [1000]> : {
set [output v] to ((output ::grey)/[1000]) ::grey
change [-illion v] by (1) ::grey
} @loopArrow ::grey
set [output v] to (join (([floor v] of ((output ::grey) * (100))) / (100)) (item (-illion ::grey) of [-illion names v] :: grey)) ::grey
- Discussion Forums
- » Help with Scripts
-
» Operators