PencilCoder

Array Destructuring!

Goals:

  • Assign variable names to elements in arrays of known length using a technique called array destructuring
  • Learn how to ensure that program statements get evaluated in the desired sequence by manipulating the animation queue with calls to await done defer()

Coding Snippets:

  • coding snippets
  • await done defer() must be called before calls to functions that return information about the current state of animation.
  • sizexy returns the dimensions of the visible screen as an array of two whole numbers. getxy returns a sprite's coordinates as an array of two integers.
  • see prints output to the test panel console. It is useful for debugging code.

Math and Computer Concepts:

  • When a program is run, Pencil Code executes all statements related to animation at once, creating schedules of tasks to be carried out in the future. Pencil Code uses these schedules, or animation queues, to display the animated results after the program finishes.
  • Functions that are not directly related to animation, such as getxy and see, are also executed before animation begins. As a result, such functions may appear to provide incorrect results. The actual problem is that they are executing at the wrong time.

Activities:

Save each of the following in a folder called Destructuring.