Code Monkey home page Code Monkey logo

Comments (7)

NathanLovato avatar NathanLovato commented on June 24, 2024 1

Where in the world is it getting cell from if cell has NEVER been declared???

Writing for cell in units declares cell.

I invite you to revisit lesson 18 and the following lesson 19 where we introduce for loops and the temporary variable you declare and name as part of the loop expression.

If you do take the time to revisit them, it'd be great if you could share a bit of feedback if you find something particularly confusing. Different people struggle with very different parts of programming courses, and while this app received lots of iterations and feedback, we're looking to improve the course with its upcoming Godot 4 remake.

from learn-gdscript.

Visnicio avatar Visnicio commented on June 24, 2024

On the suggested solution, the variable cell is inferred by the interpreter as the "current element being looped" so it does not need to be declared,
Lesson 19 has a quick explanation about this:

image

It's sorta like a "runtime declaration"

from learn-gdscript.

MilesFarber avatar MilesFarber commented on June 24, 2024

image
When will "Runtime declarations" be included in the documentation tab to the left of exercises so future students don't have to randomly guess the name?

from learn-gdscript.

Visnicio avatar Visnicio commented on June 24, 2024

My point is that your code failed the tests 'cause of the parameter that you passed to the place_unit function:
image

Your nor the suggestion naming should be the cause of tests failed, for your code to work you should have passed the position and then the unit string as described in the lesson.

So, by refactoring your code I got something like

for vector in units: # foreach vector in the dictionary
    var cell = units[vector] # the unit (in this case named as cell) is the current index that i'm looping
    place_unit(vector, cell) # place the unit at the position

Although this code now works, it's not efficient because of the naming, naming variables is a hard task and many developers struggle with it (me included)

from learn-gdscript.

MilesFarber avatar MilesFarber commented on June 24, 2024

Although this code now works, it's not efficient because of the naming, naming variables is a hard task and many developers struggle with it (me included)

Whether it's efficient or not is completely irrelevant. That is the ONLY code that should work because nowhere anywhere in the entire course are "runtime declarations" explained properly, nor does the course ever show the student the documentation for what ALL the "member variables" are, which would speed up development by many orders of magnitude, no matter what the project is. The student is just left guessing what the names are.

image
I guess i'm just not one of those developers.

from learn-gdscript.

Visnicio avatar Visnicio commented on June 24, 2024

Just to put us on the same page: "Runtime Variables" is no official naming or concept, it's just a way that I found to try to make it clear

The student is not left by himself.
Indeed, the lessons about for loops could enforce more that the variables are implicit, but I feel that lesson 19 already made it pretty clear that in a for loop you have to declare a variable that will represent the current element of the loop. Sure, you can definitely name it "dab" but why would you? When writing any loop, you first have to understand why and what are you looping though.

func run() is not a native function of the Godot Engine, so I do not see your point here that "it's not in the docs", again, lesson 19 explains that a for loop receives a variable that represents the current element of the loop, the programmer could name anything he would like. So, getting back again to the first question: cell was not a defined variable, it was inferred by the loop, it's just how the language works

from learn-gdscript.

NathanLovato avatar NathanLovato commented on June 24, 2024

Closing for now as I believe the raised point is covered in the course. Though I understand the frustration, of course, it's easy to miss or forget something, and the app doesn't have a lot of repetition built-in. It's something we hope to improve over time with its future replacement.

from learn-gdscript.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.