GDQuest / learn-gdscript

Learn Godot's GDScript programming language from zero, right in your browser, for free.
https://gdquest.github.io/learn-gdscript/
Other
2.07k stars 153 forks source link

Lesson 11 Time Delta: Rotating Using Delta Practice BUG #706

Closed DonVonDolo closed 1 year ago

DonVonDolo commented 1 year ago

When I went to multiply delta to the rotate(2) I left it outside the parenthesis but it still said I was doing it right and congratulated me and sent me on my way to the next practice where I did the same mistake and I was wrong. I didn't realize until I showed a friend who went through the course and he said that should not have said I was right.

To Reproduce Steps to reproduce the bug:

  1. Go to https://gdquest.github.io/learn-gdscript/#course/lesson-11-time-delta/lesson.tres
  2. Click on Rotating Using Delta Practice
  3. put in the code: func process(delta): rotate(2) * delta

Expected behavior Although I did not know at the time, it is supposed to tell me I was wrong and put the * delta inside the parenthesis next to the 2

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

Screenshot_20221012-094406~2

phealy3330 commented 1 year ago

This also happens with the Linux version of the learn to code app https://user-images.githubusercontent.com/13488079/196044851-50df31bc-8d04-4a70-883d-9f489644750c.mov

I think possibly the bug is in the test_rotating_character_is_time_dependent() function https://github.com/GDQuest/learn-gdscript/blob/11730a314919541de40997dad431904dde3c8515/course/lesson-11-time-delta/rotating-using-delta/TestsRotatingDelta.gd#L23

It looks like the check logic does this: var has_delta: bool = _body.rfind("delta") > 0 Does the body of the code have the string delta? Which passes

var is_in_parentheses: bool = _body.rfind(")") Does the body of the code have a close-parenthesis? Which also passes

The second check seems to pass for similar reasons: https://github.com/GDQuest/learn-gdscript/blob/11730a314919541de40997dad431904dde3c8515/course/lesson-11-time-delta/rotating-using-delta/TestsRotatingDelta.gd#L35

In test_rotation_speed_is_2_radians_per_second()

        var has_multiplication_sign: bool = _body.rfind("*") > 0
        var has_two: bool = _body.rfind("2") > 0 and not _body.rfind(".2") > 0

The code also has a multiplication sign and a 2.

Maybe these two checks can be combined into a single string to search for, something like this super ugly regex: grep -Ei "(\(\s*2\s*\*\s*delta\s*\))|(\(\s*delta\s*\*\s*2\s*\))" ( [any whitepsace] delta [any whitespace] [any whitespace] 2 [any whitespace]) OR ( [any whitepsace] 2 [any whitespace] [any whitespace] delta [any whitespace])

phealy3330 commented 1 year ago

Digging in a little more I see that the code is doing basically that check in the happy path by removing all whitespace https://github.com/GDQuest/learn-gdscript/blob/11730a314919541de40997dad431904dde3c8515/course/lesson-11-time-delta/rotating-using-delta/TestsRotatingDelta.gd#L20

But, seems like if it doesn't have the proper body it moves on to the individual checks, but if all the individual checks pass them lesson is marked as success. I cloned the repo and added in this check, seems to work ok to catch the false successes- hope this is useful

func test_regex_passes_checks() -> String:
    var regex = RegEx.new()
    regex.compile("(\\(\\s*2\\s*\\*\\s*delta\\s*\\))|(\\(\\s*delta\\s*\\*\\s*2\\s*\\))")
    var result = regex.search(_body)
    if result:
        print("REGEX hit: %s " % result.get_string()) # Would print n-0123
        return ""
    else:
        print("REGEX fail")
        return("Regex failed")

https://user-images.githubusercontent.com/13488079/196052724-6172e0dc-5db1-4285-b5fc-7a4fae42114b.mp4

phealy3330 commented 1 year ago

Working on a PR for this

NathanLovato commented 1 year ago

Thanks much! :)