Cheat Sheet

Coding For Kids For Dummies Cheat Sheet

From Coding For Kids For Dummies

By Camille McCue

Getting started with writing code is similar to learning a new language: You’ve got to know the vocabulary and punctuation and how to put those together. You also need to know how to use the painting tools and how to make buttons and other features to create a graphical user interface for your programs.

How to Create an Action Plan When Writing a MicroWorlds EX Computer Program

Writing a new computer program begins with creating an action plan. The action plan tells what smaller parts you need to make and put together to build the entire program. Your action plan should contain steps such as the following.

Planning your design and layout:

  • Define the program purpose: game, simulation, or animated scene.

  • Select or paint backgrounds on the pages.

  • Create pages or screens that your program needs: splash page, action page, and levels. Add transitions between pages.

  • Create characters if needed by hatching turtles and then selecting shapes from the Painting/Clipart palette, or painting new shapes in shape spots on the Shapes pane. (Double-click a shape spot to open the Shape Editor.)

  • Make text boxes with titles, labels, and instructions.

  • Make text boxes to show variable values. If a variable value carries over between pages, define a project variable and then make text boxes to show the project variable value.

Creating character actions:

  • In each turtle backpack on the State tab, set character attributes. This is especially useful for attributes that don’t change during the program — after these are assigned, you don’t have to set these values again. Examples include size, shape, and heading and I have variablename values. However, these values can be changed at any time during program execution, if needed.

  • In each turtle backpack on the Rules tab, add primitives or procedures to the OnClick, OnColor, OnTick, OnTouching, OnMessage, and When This Do That fields.

  • If needed, add universal color under conditionals to the background. Commands added to the background will be executed when a turtle touches a designated color.

Adding features, such as ways for users to interact and multimedia:

  • If a drop-down list will be used, create and name the drop-down list and add the items to the list.

  • If a slider will be used, create and name the slider. The slider is a variable with values that can be changed in the graphical user interface.

  • Add buttons to the graphical user interface so that users can execute the code you have written and interact with your program.

  • If needed, add audio features such as music or sound effects.

Programming the actions:

  • In the Procedures pane, write procedures that will be executed to control program flow, react to program conditions, and react to user input.

  • In the Procedures pane, write an initialization procedure to set starting conditions for program execution. This may include setting initial variable values and turtle sizes, shapes, headings, and positions, whether turtles show or hide, and whether turtles are clicked on or clicked off.

How to Use Primitives in MicroWorlds EX

Primitives are commands that MicroWorlds EX already knows. Typing a primitive into the Command Center (at the bottom of the interface) and then pressing Enter (Windows) or Return (Mac) immediately executes the primitive.

Note that some primitives need an input, such as a number, a word, or a list of words or instructions. When using these primitives, remember to check that they have the right type of input.

Primitive What Current Turtle Does
home Sets coordinates to (0,0) and heading to 0
show who Identifies name of current turtle
fd distance Turtle moves forward distance
bk distance Turtle moves backward distance
glide distance
Turtle moves distance at a
rt angle Turtle turns right angle
lt angle Turtle turns left angle
seth angle Sets turtle heading to angle
pd or pu Turtle puts drawing pen down or pen up
setc color Sets the turtle and its pen to color (for example, blue)
setpensize num Sets the size of the turtle pen
setbg color Sets the background color (for
example, yellow)
setsh shapename Sets the shape of the turtle to shapename
clean Cleans the background, but leaves all objects where they
st or ht Show turtle or hide turtle
pd or pu Turtle puts drawing pen down or pen up
wait time Waits time (in tenths
of a second)
setx xcor Sets the x-coordinate of the turtle to xcor
sety ycor Sets the y-coordinate of the turtle to ycor
setpos [xcor
Sets the coordinates of the turtle to (xcor, ycor)
repeat num
Executes the commands a total
of num times
random num Generates a random number from 0 to num – 1
setvariablename value Sets the variable variablename
to value
t1, commands Assigns t1 as current turtle; t1 executes commands
if condition[consequence] If condition occurs then
execute consequence
everyone [commands] All turtles execute commands
(not just current turtle)

How to Write Procedures in MicroWorlds EX

Procedures combine primitives and other procedures to create new commands. Procedures are written in the Procedures pane of the MicroWorlds EX interface. A procedure begins with the word to and a one-name word for the procedure. It ends with the word end, which must be on its own line. The procedure can then be executed by typing the procedure name in the Command Center, or by including it in another procedure or a button instruction or anywhere a command is used. Following are some examples of procedures.

The following code defines a procedure named redsquare that draws a red square of side length 50:

to redsquare
setc "red
repeat 4 [fd 50 rt 90]

The following code assumes that there are two text boxes: one named heads and one named tails. This code defines a procedure named initialize that sets the value of the heads variable to 0:

to initialize                     
setheads 0                     
settails 0                    

The following code assumes that there are two shapes: one named heads and one named tails. This code defines a procedure named cointoss that sets the value of the flip variable to a randomly generated number (either 0 or 1); it then shows a heads shape or a tails shape according to the outcome:

to cointoss                    
setflip random 2                 
if flip = 0 [setsh "heads]            
if flip = 1 [setsh "tails]