Discuss Scratch

105995
Scratcher
11 posts

I need help simplifying the code.

Instead of coding: if Costume # = 1 or 2 or 3 or 4 or 5 or 6 and if Variable = 1 or 2 or 3 or 4 or 5 or 6

I want to code if Costume # = 1 through 6 and if Variable = 1 through 6.
deck26
Scratcher
1000+ posts

I need help simplifying the code.

Create a list containing the range of values and check if the list contains the value.

OR check if value > x and < y where x=minimum-1 and y=maximum+1.

OR check NOT (value < min or value > max)

Last edited by deck26 (March 23, 2023 21:06:18)

105995
Scratcher
11 posts

I need help simplifying the code.

I am unsure of how this would work because the list would go up to 24 for both of them and not all of the costume #'s should be compatible with the variable.
deck26
Scratcher
1000+ posts

I need help simplifying the code.

105995 wrote:

I am unsure of how this would work because the list would go up to 24 for both of them and not all of the costume #'s should be compatible with the variable.
So go for the list option where you can omit some of the range. But what are you actually trying to do? If, for example, you have a set of costumes for a certain part of the game can you start those costume names with a specific character - eg jumping costumes start with a ‘j’.

I answered the question you asked. You then added the possibility that some numbers might be missing. Giving more detail in the first place would have saved us both time!
Spentine
Scratcher
1000+ posts

I need help simplifying the code.

You can use this.
if <not <<<(costume #) < (1)> or <(costume #) > (6)>> or <<(Variable) < (1)> or <(Variable) > (6)>>>> then
I originally started with this code:
if <<<not <(costume #) < (1)>> and <not <(costume #) > (6)>>> and <<not <(Variable) < (1)>> and <not <(Variable) > (6)>>>> then
Note that <not <(x) < (y)>> is the same as <(x) ≥ (y)>. I then used some simple boolean algebra to simplify it.
<<not <x>> and <not <y>>> is the same as <not <<x> or <y>>>
so I did that 3 times to get the final result.

Hope this helps!
vladfein
Scratcher
100+ posts

I need help simplifying the code.

105995 wrote:

I am unsure of how this would work because the list would go up to 24 for both of them and not all of the costume #'s should be compatible with the variable.

You can emulate a “switch” statement with “broadcast”:
https://scratch.mit.edu/projects/824859357/
105995
Scratcher
11 posts

I need help simplifying the code.

Spentine wrote:

You can use this.
if <not <<<(costume #) < (1)> or <(costume #) > (6)>> or <<(Variable) < (1)> or <(Variable) > (6)>>>> then
I originally started with this code:
if <<<not <(costume #) < (1)>> and <not <(costume #) > (6)>>> and <<not <(Variable) < (1)>> and <not <(Variable) > (6)>>>> then
Note that <not <(x) < (y)>> is the same as <(x) ≥ (y)>. I then used some simple boolean algebra to simplify it.
<<not <x>> and <not <y>>> is the same as <not <<x> or <y>>>
so I did that 3 times to get the final result.

Hope this helps!

Thanks! This helped a lot!

Powered by DjangoBB