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

Lesson 16, Exercise 1, godot can't understand using cell.x

Open reneawil000 opened this issue 1 year ago • 5 comments

Describe the bug Whenever I try and move the robot to the bottom right with my code, it says script verifier can't catch it.

To Reproduce Steps to reproduce the bug:

  1. Open gdscript from zero
  2. Select lesson
  3. Select lesson 16
  4. open practice
  5. copy and paste this code to get the error:

func move_to_bottom():
	while cell.y < board_size.y:
		cell.y += 1
		
	while board_size.x > cell.x:
		cell.x += 1

Expected behavior Move to the bottom right part of the board.

Screenshots If applicable, drag and drop screenshots here to help explain your problem.

Information about your device (please complete the following information):

  • Operating System: Windows
  • Browser: Chrome 107

Additional context Add any other context about the problem here. gdquest-1705514334257.log

reneawil000 avatar Jan 17 '24 18:01 reneawil000

Did you clone the project in Godot? If so, you need to use the exported app to use it, you can´t just import the project in the Godot editor.

You can follow the series in the browser here: https://gdquest.github.io/learn-gdscript/

Or download a desktop copy here: https://gdquest.itch.io/learn-godot-gdscript

NathanLovato avatar Jan 17 '24 19:01 NathanLovato

i didn't import the project into the godot editor, i'm using the web version.

reneawil000 avatar Jan 17 '24 19:01 reneawil000

Thanks for the precision! I think what could be causing this is we try to rewrite while loops to ensure they're never infinite. The rewrite may be failing when using two while loops in a row.

NathanLovato avatar Jan 17 '24 20:01 NathanLovato

I think there may be another issue here, as I ran into a similar problem. When I initially tried to write a solution for this exercise, I wrote the following:

func move_to_bottom():
    while cell.y < board_size.y:
        cell.y += 1

Essentially, the solution posted above, but without the additional loop. The script verifier couldn't catch the issue, and then I noticed the first issue -- the robot can move outside the board grid. So I fixed it:

func move_to_bottom():
    while cell.y < board_size.y - 1:
        cell.y += 1

But still no dice from the script verifier. That's when I realized the second issue: I was trying to assign a new value to the y property of the cell. Assigning a new vector as the solution suggests works:

func move_to_bottom():
    while cell.y < board_size.y - 1:
        cell += Vector2(0, 1)

For a final experiment, I changed the condition to the following: while cell.y < board_size.y - 1

This doesn't pass tests, but the script verifier helpfully tells me that the robot has moved beyond the grid. Long story short, it seems like the script verifier isn't catching attempts to assign/add values to a property of the vector where it expects you to add/assign a new vector.

NFulkerson avatar Feb 27 '24 05:02 NFulkerson