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

#1 2012-08-12 22:29:46

Zangooser
Scratcher
Registered: 2012-03-18
Posts: 1000+

Questions about a few Operator blocks

Okay, so, seeing as I'm a mediocre programmer at best, I've been working at scripting a bit; mostly looking at other peoples' projects and analyzing the code. I'm kind of puzzled by these two Operator blocks, though:

(join [hello] [world])
(( ) mod ( ))
I just want to know how they can be used, and how they work / what they do. I've seen them in a lot of complicated scripts, so I'll bet that they're worth their code.
Sorry if I happened to have asked a tough question. XP


http://www.blocks.scratchr.org/API.php?action=random&return=image&link1=http://i.imgur.com/O0efo.png&link2=http://i.imgur.com/B1KzK.png

Offline

 

#2 2012-08-12 22:34:32

berberberber
Scratcher
Registered: 2012-03-08
Posts: 1000+

Re: Questions about a few Operator blocks

Join adds the 2 strings.

So,

when gf clicked
ask [what's your name?] and wait
say (join [hello,] (answer))
Would have the sprite say the answer.

Modulo, or mod, gives the remainder of the 1st number divided by the second.

So,
((28) mod (9))
gives 1.

Last edited by berberberber (2012-08-12 22:34:42)


http://i47.tinypic.com/2iaa73k.png

Offline

 

#3 2012-08-12 22:40:45

Zangooser
Scratcher
Registered: 2012-03-18
Posts: 1000+

Re: Questions about a few Operator blocks

berberberber wrote:

Join adds the 2 strings.

So,

when gf clicked
ask [what's your name?] and wait
say (join [hello,] (answer))
Would have the sprite say the answer.

Modulo, or mod, gives the remainder of the 1st number divided by the second.

So,
((28) mod (9))
gives 1.

I don't quite understand what you mean for the mod block. Isn't that the same as the division block?  hmm


http://www.blocks.scratchr.org/API.php?action=random&return=image&link1=http://i.imgur.com/O0efo.png&link2=http://i.imgur.com/B1KzK.png

Offline

 

#4 2012-08-12 22:42:38

berberberber
Scratcher
Registered: 2012-03-08
Posts: 1000+

Re: Questions about a few Operator blocks

No, it gives the remainder.

((28) / (9))
gives 3, the answer.
((28) mod (9))
gives 1, the remainder.

Last edited by berberberber (2012-08-12 22:42:46)


http://i47.tinypic.com/2iaa73k.png

Offline

 

#5 2012-08-12 22:49:19

TorbyFork234
Scratcher
Registered: 2012-03-01
Posts: 1000+

Re: Questions about a few Operator blocks

The join block, joins to strings together. I use it a lot in Scanning stuff. Here's an example of a use: you have a picture with black squares and white squares (like those things you scan everywhere with your iPhone). You want to be able to save it in data. So, you say that black=1 and white=0. So you set it up so that it would move 1 pixel, sense if it's touching black or white, and record it. Well, how do you record it? You have a variable and you add this script:

 
if <touching color [#FFFFFF]?>
set [var v] to <join (var) [0]>
else
set [var v] to <join (var) [1]>
end
that way it would take the stored value it has, let's say it's 10010101, and add either 1: 100101011, or 0: 100101010. You would be able to do that another way, but this way is more understandable.
I use the join block like that in this project. Download and study the scripts if you still don't understand.
Another way people use it is to put something for looks, like percentage. Let's say they have a variable: score, and a variable: actualscore. You would have score show, have actual score have a number from 0-100, then do this:
 
set [score v] to <join (actualscore) [%]>
For the
 <()mod()>
block, it's like the
 <()/()> 
block, but instead of reporting the answer, it reports the remainder.
It's a good use when you implement your own direction system, and you want it to stay within 0-360. So, you would have this:
set [direction v] to <(directionvar)mod(360)>
That way, if direction ever get's below or above 360, it'll set it to it's right spot in 0-360.


Hope that helps!

EDIT: Wow! epic outpost

Last edited by TorbyFork234 (2012-08-12 22:52:20)

Offline

 

#6 2012-08-13 18:16:58

Zangooser
Scratcher
Registered: 2012-03-18
Posts: 1000+

Re: Questions about a few Operator blocks

Sorry to bump a (somewhat) old topic, but I found another one that's puzzling:

round ( )
When I tested it out by making a script like this:
when gf clicked
say (round (10))
...all it said was the number 10, so apparently, no calculations were made. I've tried it with other numbers, too.
What's it for?


http://www.blocks.scratchr.org/API.php?action=random&amp;return=image&amp;link1=http://i.imgur.com/O0efo.png&amp;link2=http://i.imgur.com/B1KzK.png

Offline

 

#7 2012-08-13 18:20:20

Wes64
Scratcher
Registered: 2011-08-19
Posts: 1000+

Re: Questions about a few Operator blocks

Zangooser wrote:

Sorry to bump a (somewhat) old topic, but I found another one that's puzzling:

round ( )
When I tested it out by making a script like this:
when gf clicked
say (round (10))
...all it said was the number 10, so apparently, no calculations were made. I've tried it with other numbers, too.
What's it for?

rounding a decimal

round (5.2) = 5
round(5.7) = 6


Experienced 2.0 Tester: Ask me questions!
Using Firefox 13.0, Flash plugin version 11.4.402.287, and Windows XP Professional.

Offline

 

#8 2012-08-13 18:21:04

berberberber
Scratcher
Registered: 2012-03-08
Posts: 1000+

Re: Questions about a few Operator blocks

It rounds the number.

So,

say (round (8.7))
would actually say 9.


http://i47.tinypic.com/2iaa73k.png

Offline

 

#9 2012-08-13 18:22:45

Zangooser
Scratcher
Registered: 2012-03-18
Posts: 1000+

Re: Questions about a few Operator blocks

berberberber wrote:

It rounds the number.

So,

say (round (8.7))
would actually say 9.

Oh. Thanks, ber! The names of the blocks are just so vague, it's hard to tell what they stand for. XP


http://www.blocks.scratchr.org/API.php?action=random&amp;return=image&amp;link1=http://i.imgur.com/O0efo.png&amp;link2=http://i.imgur.com/B1KzK.png

Offline

 

#10 2012-08-13 18:26:56

Wes64
Scratcher
Registered: 2011-08-19
Posts: 1000+

Re: Questions about a few Operator blocks

Zangooser wrote:

berberberber wrote:

It rounds the number.

So,

say (round (8.7))
would actually say 9.

Oh. Thanks, ber! The names of the blocks are just so vague, it's hard to tell what they stand for. XP

if you right click a block and select "Help" there will be a blurb describing the block (if you didnt know)


Experienced 2.0 Tester: Ask me questions!
Using Firefox 13.0, Flash plugin version 11.4.402.287, and Windows XP Professional.

Offline

 

Board footer