Step 7: Coding the Lightsaber On (Part 1)

Goal:


Now that our app has all the components it needs, we now need to code these part.

First we need to make our light saber “activate”. We are going to simulate this by having the canvas draw a line that will look like a lightsaber blades.

We also need to create a variable that tells our code whether the lightsaber is activated or not.

Steps:

  1. From Variables, place initialize global block on the screen and type “saberOn” in the box.
  2. From Logic, attach a false block to the end of the initialize global saberOn block.
  3. From Canvas, place a when Canvas1.Flung block onto the screen.
  4. From Control, place a IF statement block inside of the when Canvas1.Flung block.
  5. From Logic, attach a =(equal) block to the IF portion of the IF statement block.
  6. From Variables, place a get block in the left side of the =(equal) block and set it to saberOn.
  7. From Logic, place a false block in the right side of the =(equal) block.

Code: