Comments (7)
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.
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:
It's sorta like a "runtime declaration"
from learn-gdscript.
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.
My point is that your code failed the tests 'cause of the parameter that you passed to the place_unit
function:
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.
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.
I guess i'm just not one of those developers.
from learn-gdscript.
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.
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)
- Since godot is coming to mobile,put a pop up keyboard. HOT 1
- Lesson 4 Paragraph still in english while using spanish version
- Practice 7.2 Drawing Squares at 3 positions
- Lesson 25 - Displaying the Inventory Items
- Stress marks marked as unknown character
- Toggle for smooth scrolling feature?
- The keyboard doesn't show up in mobile (im using tablet (Xiaomi pad 6)) HOT 2
- Hey. I try to do the course on my ipad in my favorite cafe. But i can change the code, because i can’t find the keyboard option. When i click on the intended area where i want to delete something or type, the keyboard option doesn’t pop up. What am i missing? Or isn’t it available on ipad? HOT 4
- Error in code example logic in first lesson (1. What code is Like)
- Cannot open the .dmg
- 20.2 Variable not defined
- Wrong execution and visuals lead to success in L7P2
- My keyboard doesn't come on when ever it's needed
- Tests passing when they shouldn't - Claryfying code using variables (Lesson 12)
- Worse visibility in Firefox (lesson-17-while-loops)
- Lesson 17. Introduction to For Loops: Explain why we need to subtract 1 to board_size.x HOT 2
- Cut, Copy and Paste in the internal editor uses Control-X etc. instead of Command-X on MacOS Computers. HOT 1
- /lesson-23-append-to-arrays/practice-B7tKRHJM.tres array pop behavior
- Lesson 7 Exercise 2 issue HOT 1
- 22 practice 1 - app crashing/freezing
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from learn-gdscript.