Skip to Content

Color - Finding out the code numbers

« How do I...?
11 replies [Last post]
Anne Carlill
Member

Hi,

I wish to use numbers and algebra to change the colors in my program. How do I find numeric codes for the primary colors and black?

 

Replies
Mike Owen
Member

Al- I see examples of the "For Loop" in the BYOB manual, but it is not one of the standard control commands for either Scratch nor BYOB.

Do you have to make it?

Al Gifford
Member

It is so useful you will want to make it!  Besides you will learn a ton about building your own blocks in the process and that will help you with encapsulation in your later projects...

go to the variables tab and select "Make a block" (gray button at the bottom)
select "control" as your category - choosing a category will determine where your created block appears later, so pick something that will sort it where you want it
leave command type and "for all sprites" selected
in the text area type "for %i = %begin to %end %action" - anything you precede with a percent sign is a variable
when you hit enter it will take you to the block editor, from here we will modify each variable
click on the variable "i" and then in the "edit input name" dialog choose the little black triangle on the far right - this is where you set properties and validations for your input variables
for "i" check the checkbox "make the internal variable visible to caller" - this will make it so you can access the variable i inside the for loop
go into the properties of begin and end and give them default values (1 and 10)
do the same thing for action and select the checkbox for c-type
now for the code of the block:
(someone seems to have revoked my ability to upload images...so I will describe it to you)

set [ i v] to (begin)

repeat until < (i) > (end) >

  run action

  change [ i v]  by (1)

 

hope that makes sense... Good Luck!

 

Al

Mike Owen
Member

Oops- Seem to be getting my replies in the wrong places. Down below I added that I found the Tutorial on how to make one. Still haven't found out why mine never stops even though the two seem the same.

Update: Deleted everything that was done in the Website Tutorial 1, created one of my own, and now everything works. Mine now counts either positive or negative depending on the initial initial values of Start/Finish.

Thanks for the support.

Thinking on creating one with a step value in case I want to skip values. :)

Al Gifford
Member

Let me first state, all of this is self-taught, so the BYOB gurus may have different (a.k.a. correct) terminology for things.  I am probably not too far off the mark however.

If things go wonky that is an opportunity for you to learn the debugger....Throw a debug block at the top of your execution chain and when you run you will be dropped in to the debugger (ok, no fancy breakpoints, inspectors, manipulation, in fact it is a pretty sad little debugger, but it is better than nothing at all!) The button on the left is "run" which is basically your "I'm done button".  The one on the right with the arrow pointing to a flat line is your "step into" and it is your bread and butter (later on you may see a double chevron to the right of that which is your "step over/out" which will allow you to jump over blocks you have created, but I do not wish to confuse things so ignore that for now)

The arrow pointing to the line is the one we will be using...each time you click it, it will show you a block of code and then it will drill down to the inner most function call/variable... When you reach the inner most value it will show it on the screen twice.  The first time is so you know what block is being evaluated, the second time is after evaluation.  If you click the variables button, it will allow you to inspect local variables by placing your mouse over the variable name in the list and waiting for a little popup with the value inside.  if a value has just been evaluated, at the top there will be a "report value" and a mouseover there will give you the evaluated result.

It is a little confusing at first when it jumps inside a block you created (like the for loop), but if you play with it a bit you will get comfortable with it.  You can easily follow the flow to determine why your loop is never ending (Did you not use a negative number in your "change variable by n" block?) You should be able to see that kind of error here.

 

Good luck!

 

Al

Mike Owen
Member

Thanks again Al- Had fun watching the debugger.

The problem I encountered was with the Tutorial Author's use of the "The Block" in his video. Quite simply, I could never get it to work using the Call() as described in the video because I FAILED to put the "repeat until call(test)" in , just a "Repeat until (test)". My Bad :(

I used an alternative method for my students that didn't require "The Block", and moved on, but backed up and showed them this way also.

A minor problem that test subjects in my highschool class encountered was trying to understand exactly what the "run[action]" actually did. That helped me to some extent, because I could then explain that the "Actions" were going to be all of the commands that would eventually reside inside of the For Loop C-Block that this code generates, and the current value of "i" would be passed to those commands upon each iteration. It also gave me a chance to demonstrate what happens if you switch the order of the "run[action]" and "set (i)" commands.

Life is Good, sometimes better if fully understood ;-)

 

Anne Carlill
Member

Hi Al,

I'm back later the same day having produced the program you outlined to me.  I've written my program using 'shade' as well so I can get black. I couldn't work out how to paste my script here so I had to upload it to scratch.mit.edu . It is called ColourOfSprite.

Thanks so much for your help. I would have never been able to program it myself!

Al Gifford
Member

That is awesome...Even cooler is I can hear your awesome english accent over the forum (colour vs color)... :) love it!!!

 

I am glad that worked for you.  It is a technique I teach my students, it is often easier to "ask the code" than try to find the answer in a book, forum, or friend.  And the lesson seems to stick in your memory better.  You just have to overcome a fear of failing or breaking something.  Just save your work and dive in!!! (That save your work part is the difference between bravery and lunacy :P)...

 

Good Luck!!!

 

Al 

Anne Carlill
Member

Hi Al,

Thanks. I am really enjoying programming in Scratch. I'm a grandmother so I'm hoping to pass my enthusiasm on to my grandchildren.

 

Thanks so much,

Anne 

Anne Carlill
Member

Hi Al,

Thanks very much. Of course, that's a great way to find out the colours!

I really appreciate your help.

Anne

Leeds, UK

Al Gifford
Member

The easiest way is to "ask the code"... Write a quick program that varies the color... For example:

 

You will see around 200 it "loops" the color palette....

 

Enjoy!!!

 

Al 

Mike Owen
Member

Hello Again- Haven't used BYOB  much in my classes yet, just Scratch. I did locate the Tutorial 1 that describes how to build a for loop. Although I did follow the instructions, and my code appeared to be correct, I could never get the loops to stop regardless of whether they went up or down.

Not the kind of thing I want to start my students off with.