Lab 4

Click HERE to view my Problem #1

Click HERE to view my Problem #2

Click HERE to view my Problem #3

Lab 4 Overview

This lab was focused on the use of variables in Scratch. Problem 1 asked us to make a sprite change costumes. As the sprite is changing constumes, there should be two buttons on the screen. When one button is clicked, the sprite will change costumes faster, and when the other button is pressed, the sprite will change costumes slower. We were supposed to do this with the use of one variable. Problem 2 had us create a program in which a sprite asks the user questions. The answers you type to these questions should be stored as variables. When the user is finished answering questions, another sprite will appear on the screen. Now the two sprites on the screen should have a conversation about the user, using the answers you gave in their conversation. Problem 3 involved finding the distance between two sprites. With two sprites on the screen, and their coordinaes stored as variables, the program should run the distance formula, and one sprite will saw what their distance is from the other sprite.

My Solution

My solution to Problem 1 was first getting s sprite that has multiple costumes. Then, I created a variable for all sprites named "speed". Within the first sprites script, I set the speed variable to 1. After this, I made a forever loop having the sprite switch costumes, waiting after "speed" seconds. This means that whatever the speed variable is, the sprite will hange costumes at that number in seconds. I then made 2 more sprites. When one of them is clicked, the speed variable goes up by 0.25, meaning the first sprite will change costumes slower. The other sprite, when clicked, will make the first sprite change costumes faster by .25 seconds. My solution to Problem 2 was to have a sprite ask a question to the user, using the sensing bar. After the question is asked, the user of the program types in the anser. I created 4 variables, and when each question is answered, the variables are set to whatever the user typed in. After the questions are done, another sprite shows up on the screen. Using the variables, the two sprites have a conversation about the user of the program. My solution for Problem 3 was to first put two sprites on the screen. I then made four variables; x position of sprite 1, y position of sprite 1, and then the x and y positions of sprite 2. After these variables are set, I have the program run the distance formula between sprite 1 and 2. I have the sprites move a few different times, and calculate their distance each time.

Questions

1)Variables in math and computer programing similiar because you can use other variables to solve a variable, but in computer programming, a variable can only be one thing at a time.

2)A variable can effect all sprites or only one sprite.

3) A variable can only store one value at a time.

4) The code will just set "value_1" variable to value_1 because "value_2" is being set to value_1. It is not working as intended because variales can only be doing one thing at a time.

5) Variable "temp" is being set to temp becuase first it is being set to value_1, then "value_1" is being set to value_2, then "value_2" is being set to temp.

Click HERE to return to homepage.