Lesson 16, Exercise 1, godot can't understand using cell.x
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:
- Open gdscript from zero
- Select lesson
- Select lesson 16
- open practice
- 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
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
i didn't import the project into the godot editor, i'm using the web version.
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.
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.