Discuss Scratch

Za-Chary
Scratcher
1000+ posts

New Block: () Is Even/Odd?

Sheep_maker wrote:

If someone is dealing with even vs odd, they're probably already limiting their domain to integers

However I think also adding an odd? block would help with readability
I would assume this as well. But to my knowledge, there isn't a block existing in Scratch that accepts number inputs, but does not accept non-integer inputs. If any number were to be input into this proposed boolean, I would think that some sort of true/false output would be given.

So, as I mentioned, “is 1.5 even” would return “false”. This does not mean that it is odd, however. Thus I think we would also need an “is odd” boolean alongside the “is even” boolean, provided that we would implement such a suggestion. I agree with you that adding both would help with readability (after all, a subtraction block exists for readability purposes even though you can just use the addition block).
Sheep_maker
Scratcher
1000+ posts

New Block: () Is Even/Odd?

Za-Chary wrote:

I would assume this as well. But to my knowledge, there isn't a block existing in Scratch that accepts number inputs, but does not accept non-integer inputs. If any number were to be input into this proposed boolean, I would think that some sort of true/false output would be given.
I just found out that in 3.0 the
(letter (1) of [apple])
block does not allow you to put a decimal point, negative sign, or “e” in the number input (even the number pad that appears for touch users reflects this), unlike the other number inputs. This might mean that Scratch supports integer inputs. (The repeat block has a similar special integer input)

The list blocks have similar inputs except for some reason they allow the negative sign even though negative indices don't do anything. (The go forward/backward _ layers block has a similar input, and negative numbers go the opposite direction)

I've also noticed that the note input (such as the one in the Music extension) turns red when the given number is invalid, and it tries to correct the value when you click away, but other inputs don't do that

TIL!
coder2045
Scratcher
1000+ posts

New Block: () Is Even/Odd?

Nambaseking01 wrote:

45afc4td wrote:

Is this better?

<<(([floor v]of(x))mod(2))=(0)>and<([floor v]of(x))=(x)>>
<<(([floor v]of(x))mod(2))=(1)>and<([floor v]of(x))=(x)>>

Is this supposed to be sarcasm? Because that workaround is more complex than the ones suggested,



Should I ask you why you want this block when the workaround is obvious? Fine, some blocks might actually be there even though the workaround is simple but this one is maths. We can't sit adding every single mathematical calculation into Operations just because there already exist a few.

I might as well add binary calculators, Pi radius counters, and so on… Don't you understand that maths is almost endless?
45afc4td said that
<((0.99999999999999985) mod (2)) = [1]>
returns true even though 0.999999999999985 isn't an integer so it isn't odd nor even.
EDIT, 3 years later: It's caused by rounding errors.

Last edited by coder2045 (Jan. 15, 2023 21:33:14)

Sheep_maker
Scratcher
1000+ posts

New Block: () Is Even/Odd?

coder2045 wrote:

45afc4td said that
<((0.99999999999999985) mod (2)) = [1]>
returns true even though 0.999999999999985 isn't an integer so it isn't odd nor even.
It should be assumed that when one is asking for even vs odd, they're already limiting their domain to integers, so -0.99999999999999985 is irrelevant.
BB1000000000
Scratcher
34 posts

New Block: () Is Even/Odd?

I personally don't want to have 2 separate blocks that preform the same function, just that the other one returns if the number is odd, and not even. This is why I'd like to have the even/odd blocks combined into one single block with a dropdown input where you can select even or odd.
fdreerf
Scratcher
1000+ posts

New Block: () Is Even/Odd?


LastContinue wrote:

Literally everything is workaroundable, the ATs figured out the minimum amount of blocks needed to use Scratch at one point, all else is “workaroundable”.
It's not that there's a workaround. It's that there's a simple one.
Slammamy
Scratcher
1 post

New Block: () Is Even/Odd?

ok
panda-wat
Scratcher
100+ posts

New Block: () Is Even/Odd?

This is a good idea, but there is an issue with decimals. Maybe it could just report “0”, like booleans for a custom block do when clicked?
SuperCappy
Scratcher
500+ posts

New Block: () Is Even/Odd?

Slammamy wrote:

ok
excuse me did you just necropost
lovecodeabc
Scratcher
1000+ posts

New Block: () Is Even/Odd?

The file size is NOT lowered:
In javascript, you use
// set to anything you wanna, just returns NaN if you enter string(or error? i tried on my website but...)
function IsEven(num){
if(num % 2 == 0){ 
return true;
}else{
return false;
 }
}
For your block and
 if num % 2 == 0{
//done
var even = true;
//etc. etc
}
for workaround

Last edited by lovecodeabc (Nov. 7, 2020 15:10:51)

liamboyhalo
Scratcher
500+ posts

New Block: () Is Even/Odd?

Support, even though it's pretty easy to workaround.
831985
Scratcher
100+ posts

New Block: () Is Even/Odd?

I agree! It could be helpful, and I thought so, in fact I made a topic about this but I did not know this one existed…
Tronche2Cake
Scratcher
100+ posts

New Block: () Is Even/Odd?

if <(round ((n) / (2))) = ((n) / (2))> then
even
else
odd
end
linearlemur
Scratcher
500+ posts

New Block: () Is Even/Odd?

“new sCraTCHeRS WiLL BE CONfUSeD” No. That is not an excuse to add a whole new block with a 2 block workaround. Newcomers should be able to develop the skills to figure out the workaround on their own. No popular programming languages have a built in function like that. Why should Scratch? When they get thrown into the world of text-based programming, they'll be expecting this to be a built in function, but won't know what to do when there's no function like that. Also, by using this workaround, they'll probably understand what modulus is.

ajskateboarder
Scratcher
1000+ posts

New Block: () Is Even/Odd?

There's an easy workaround with the modulo operator which is commonly used in text programming (good for people leaving Scratch to pursue other languages)

when flag clicked
set [number v] to [2]
if <((number) mod (2)) = [0]> then
say [Even number] for (2) secs
else
say [Odd number]
end

No support.

Last edited by ajskateboarder (Jan. 14, 2023 21:49:37)

PkmnQ
Scratcher
1000+ posts

New Block: () Is Even/Odd?

The mod block is useful and New Scratchers should learn how to use it. No support.
clay231
Scratcher
5 posts

New Block: () Is Even/Odd?

BB1000000000 wrote:

The block would be a Boolean that reports if the specified number is even/odd. If so, it would return true, if not it would return false. Such a block could be placed in the Operators category. This is what the block might look like:
<(10) is [even v]? ::operators>
A workaround may be to use the
() mod ()
along with the
[] = []
.


<((number) mod (2)) = [0]>

Mod is that the first number divided by the second number and it reports the remainder (e.g. (10) mod (3) = 1).
If there was no remainder, it would be 0, which is even, and if there was a remainder, it would be anything above 0, which is odd

Last edited by clay231 (June 10, 2023 16:09:01)

clay231
Scratcher
5 posts

New Block: () Is Even/Odd?

when I receive [go]
broadcast [go]
create clone of [myself]
when I start as a clone
broadcast [go]

Last edited by clay231 (June 9, 2023 22:58:01)

medians
Scratcher
1000+ posts

New Block: () Is Even/Odd?

You can just do this:
define (number1) is even/odd
set [result v] to [neither]
if <((number1) mod (2)) = [1]> then
set [result v] to [odd]
else
if <((number1) mod (2)) = [0]> then
set [result v] to [even]
end
end
clay231
Scratcher
5 posts

New Block: () Is Even/Odd?

BB1000000000 wrote:

WindOctahedron wrote:

I don't think that it needs to be added, because the workaround is very easy to make:
<((n) mod (2)) = [0]> // outputs "true" if the number is even
<((n) mod (2)) = [1]> // outputs "true" if the number is odd
That's what I said at the end of the post: you can use the
() mod ()
and the
[] = []
blocks together to recreate the function of the supposed new block, but I think that the new block would be easier for New Scratchers to understand and comprehend, and to reduce the file size of more complex projects.


you could just use

if <<not <(round ((number) / (2))) = ((number) / (2))>>> then
broadcast [number is odd]
end

Powered by DjangoBB