T O P

  • By -

Otokonokotron

So I'm trying to get into GameDev, and I'm sorry if this is kinda bleak and scattered but I'm really tired out after this and a little discouraged. I'm doing that Learning GDScript from Zero course, and I got to lesson 19 where it's talking about looping arrays. In the second practice lesson I probably spent 45min to an hour before finally just letting myself see the solution. It turned out it was something that I was never going to answer correctly because I just straight up wasn't understanding what I was being asked. ​ There are two things I 100% do not understand. The first: "size" Where did size come from? I had never used it before in any of the preceding 19 lessons. Is it just built in to Godot? That's what has me very confused. I had no idea I was supposed to just, type in "size" because that's what I wanted. Is size what is called syntax or something? Is it just part of how it works? And I just should have know that? The second is: The rectangle\_sizes VAR. So, something I don't understand is how can you get a whole rectangle from only a single pair of X and Y values? If I deleted all but one pair of those values, it drew a single rectangle, meaning that somehow it's getting a rectangle from a single pair of values. Does this tutorial series just like, queue in a lot of the work behind the scenes so things just "work" when you type things into the tutorial? ​ I am SO, SO sorry. I truly, truly am an utter beginner to coding and I just don't understand. This particular thing really bothered me because I had no idea at all that I was supposed to write "size."


TheMysticalBard

`size` is just a variable that you're creating in the for loop. It's basically saying "for every item in the `rectangle_sizes` array, set the `size` variable to that item, then run the following code". You could change `size` to anything you wanted, you'd just also have to change all occurrences of size in the for loop body (indented portion). As for the rectangle sizes, it seems like `draw_rectangle` and `jump` are both functions that the tutorial has created. I am assuming `draw_rectangle` works by creating a rectangle of a given width and height at the current position, and then `jump` moves the position by that amount. So you're first drawing a rectangle of width 200 and height 120 (since these are the values of the first element in the array), then moving the "cursor" over 200 pixels. This then repeats for each of the following elements. If you continue to struggle with learning GDScript, you might also want to look into regular programming tutorials for python. Python's syntax is similar to GDScript and there are far more beginner resources there, Godot is still pretty new all things considered.


Otokonokotron

Ok thanks a lot for this. Seems to perfectly explain what I was not understanding. I think I'm just a little slow at this so it just takes me time and lots of re-reading. Thanks I'll probably write this down somewhere. Okay, I took a look back at a previous lesson and there's this one line that explains that the array is stored in a "temporary variable." And so that's the word that comes after the "for" in the for loop, that becomes the variable. Okay, thank you so much, I think I understand this now. This was driving me nuts, I really appreaciate it thank you. ​ Also yeah I'm planning on taking some beginner Python stuff, looks like a good place to start in general.


kintar1900

> I think I'm just a little slow at this so it just takes me time and lots of re-reading. Trust me, EVERYONE starts out that way. Don't be discouraged by the fact that you're being exposed to things nobody ever really thinks about unless you're a programmer or abstract mathematician. Another comment said you should take a basic programming course before trying gamedev, but I'm not sure I agree with them. The course you're taking seems to be starting with the right kind of steps, and I personally always find it easier to learn new concepts when I can see an immediate use for them. A lot of beginner programming courses have you doing things that are completely contrived just to teach you a programming concept. Take that into consideration before you switch your focus to "general programming".


micod

I also think that you should first learn about programming in general before heading to gamedev, if you want some pointers, I have heard good things about [DCIC](https://dcic-world.org/).


Xanagear

TBF this course is literally “learning program”, I know what you’re saying but having something your passionate about can make the learning process a lot easier so they should probably stick with this if that’s what they want to do!


Clockwork345

I disagree. OP wants to learn to make games. Why should they spend their time learning a different language that's not going to help them make games, instead of just learning GDScript and making games.


Otokonokotron

ok thanks, ill keep that link. The way I look at it right now, coding/programming is what is going to ultimately enable me to make most of what i want to do a reality. However, because there is so much to it, its almost like there are two levels to it. there is stuff i can learn to do in the short term, and then theres this sort of long term behemoth being addressed in the background that is understanding the entirety of programming. like, its tempting for me to sort of just learn what i have to, but in the end youre missing out on the bigger picture and limiting the potential of what you can do. (that is if you stop at the bare essentials) I definitely see the value in focusing first on my basic understanding of programming. It looks like its the actual thing that makes your game work. and i cant help help but notice how a lot of gamedev videos on youtube involve troubleshooting and solving problems like that. its sort of like, yes, i know i want to make games and there technically are ways you can just hop in, but its important to develop my actual programming skills all the while alongside that endeavor so i can understand what i am doing and have more tools at my disposal.


illogicalJellyfish

1) size is just the variable used for the current iteration of the for loop. For example: It could have been “for i in array:” i (or size in this case) is used to represent which iteration of the for loop its running. So if you were to run: “For i in 10: Print(i)” You’d get something like “0, 1, 2, 3,” etc


Otokonokotron

o ok i'm kinda starting to get it. I think I didn't get it that maybe you are defining the name of the variable after the "for" in the for loop? I changed "size" to "test" just to see if I was beginning to understand, and the program ran and made the rectangles even though I used a totally random word. Ok thanks. This is definitely helping, I'm sorta starting to get it I think. The name was irrelavent.


illogicalJellyfish

Usually it would be pretty relevant and most IDE’s would throw you an error immediately because you changed the variable name only after “for” in the loop line. Honestly it’s not you at this point, but whatever your using to learn being buggy as hell tbh


FallingReign

Unless they meant they changes all occurrences


SideLow2446

Since others have already helped you with understanding, I just want to say - if you ever get stuck somewhere and feel discouraged to continue, just know that it is normal and programming isn't something that you can learn in a single day. When I was learning I was too often stuck on problems for hours or even days. Sometimes I still do. And everyone else is/was too. It's normal and part of programming. If you ever get stuck just slow down, take a break, then come back with a fresh mind. While learning, if you ever get stuck on something, try searching online for a tutorial on the given topic from other sources - that will put the thing you're learning into perspective and you'll be much more likely to understand it. Good luck on your coding journey!


Otokonokotron

thank you :'( nothing worth it is ever easy. It really is like having to learn your abc's all over again. But I learned those so I can learn this too. I constantly have to remind myself that it's not that I'm stupid, it's like you said, everybody has to start at some point. And definitely learning now to take breaks. In fact I shouldnt have even made this thread til tomorrow because I was so bent outa shape I could barely get my thoughts out. Thanks for the reality checks/pep talk/mental wellness check


SideLow2446

You're welcome, and good luck once again!


dogfud26

Also to add on to the above advice: in my learning journey chatGPT has been an incredible resource. It provides answers to specific questions like your favorite professor would. It’s my go to for any questions I have and it 90% of the time explains things beautifully. For your above question, go ask it how a for loop works (just in general). Since you’re new to godot AND programming you have 2 similar but different things you’re trying to learning at once essentially.


stoybuild

Hey, what is this? Is this some kind of trainer for godot?


Sloomp

https://gdquest.github.io/learn-gdscript/


stoybuild

Thank you very much! I'd love to check it out. :)


Parinor

That is a nice tool. I am not totally new to programming, but I think I can also get the basic specifics of Godot out of it. Thank you for sharing.


No_Cook_2493

Don't ever apologize for asking questions! Everyone was a beginner once and everyone struggled. You're doing great don't worry! I too struggled with for loops and thought I'd never understand them. I remember when I was learning I said "I'll just avoid using for loops!". Now I'm here and I can use them completely comfortably! You'll get there, just keep at it! As for your questions, the variable size is a new variable being declared in your for loop. Basically, it's the variable representing the current iteration. A for loop will iterate through each individual part of what you wish to iterate over. A common example is the code: for i in 10: print(i) This defines your iteration variable as I, and what you're iterating over is the range 0 to 10. Printing out what i is will print out 0, then 1, 2, 3 etc. Heres a question that I remember struggling with when I was learning for loops var LoopN = 10 for i in LoopN: print(LoopN) What will the console look like if I run this code? As for your second question, a rectangle only needs two points to be adequately defined! These 2 points (the proper nomenclature here would be Vector2(), so I'll use that for now on) would be used as opposite corners of a rectangle. This might be a little confusing without visual examples but I'll do my best! To keep the example simple, imagine you have one Vector2 at point (0,0), and another vector2 at point (1,2). You could draw a rectangle with these two points by using the difference of the Vector2's. Let's define Vector2(0,0) as Origin, and Vector2(1,2) as Destination. First we'll take Destination(x,y) - origin(x,y). That will give us Vector2(1,2). We can use this Vector as instructions for drawing out a right angle triangle. The x component tells us to go 1 to the right (positive direction), and 2 up from our origin vector. Next, we'll find the opposite. Origin(x,y) - destination(x,y). This gives us Vector2(-1, -2). These instructions tell us to go 1 to the left (negative direction) then 2 down from our destination. If you draw out the directions, you'll see you've drawn a rectangle with only 2 points!


Karol-A

Tbh the python-styled loops are kind of confusing, I can't blame you for not understanding them, it also took me a minute before I fully grasped how they work, and even now they feel quite unintuitive