learn-gdscript icon indicating copy to clipboard operation
learn-gdscript copied to clipboard

Lesson 19 Practice 2: "size" is not identified as the necessary variable in the lesson's instructions

Open Huffy-Henry opened this issue 1 year ago • 1 comments

The solution for Practice 19.2 requires the use of the "size" variable, but nowhere in the lesson, practice instructions, or hints is the "size" variable mentioned. This means that the user has to guess the variable to search for in the "rectangle_sizes" array.

I had the formula (almost) correct from the start, but because I had no idea what the appropriate variable's identifier was, I thought I got the syntax completely wrong and tried everything under the sun to fix it. Instead, I was supposed to guess that "size" was the appropriate identifier instead of "rectangle" or (as had been used in previous lessons) "number."

For example, I would type:

func run()

| for rectangle in rectangle_sizes: | >| draw_rectangle(rectangle_sizes.x, rectangle_sizes.y) | >| jump (300, 0)

or:

func run()

| for number in rectangle_sizes: | >| draw_rectangle(number.x, number.y) | >| jump (300, 0)

and because neither of those worked, and I had no idea what the correct variable to use was, I messed with the syntax until I just gave up and checked the solution.

Huffy-Henry avatar Dec 30 '24 20:12 Huffy-Henry

Same problem

CodeWithCODFY avatar Jan 01 '25 12:01 CodeWithCODFY

In this instance, ''size'' is not a required var name, check your syntax:

for rectangle in rectangle_sizes picks a ''rectangle'' element for each element in the rectangle_sizes array, so you have to access ''rectangle'' in your solution:

for rectangle in rectangle_sizes:

    draw_rectangle(rectangle .x, rectangle .y)

    jump (300, 0) 
Image

StanleyAlbayeros avatar Oct 22 '25 18:10 StanleyAlbayeros

Thanks for answering @StanleyAlbayeros.

It can be a bit confusing when you're getting started, but when you define a for loop, the first name that you write after the for keyword is a variable that you create yourself. That is the name of each value in the rectangle sizes array.

So here if you write: for current_rectangle_data in rectangle_sizes:

This means that in the loop, current_rectangle_data is a pointer/cursor to individual values in the rectangle_sizes array:

  • On the first loop iteration, it will be equal to Vector2(200, 120)
  • On the second loop iteration it will be equal to Vector2(140, 80)
  • ...

Best of luck with your code learning journey!

NathanLovato avatar Oct 24 '25 08:10 NathanLovato