DaveTheCoder Thanks! With the is_empty and active to combine those would mean I'd have to duplicate is_empty in order to initiate a reset func that I have in place, so for me it is best to keep those seperate but to streamline them like you suggested. Thanks so much!
Array[0] causing invalid index error
Zini The last example isn't correct. The else branch still accesses the array.
No, the else branch does not access the array.
Here's another way:
var active: bool = not arr_ship.is_empty() and arr_ship[i].active
accel.visible = active
decel.visible = active
turn_l.visible = active
turn_r.visible = active
DaveTheCoder Right. I see what you mean.
- Edited
@xRegnarokx You could benefit from taking a basic programming course, preferably one that's focused on Python programming language whose syntax is very similar to GDScript. I'm saying this because it seems like you constantly struggle with fundamental logic and control flow of your program. Focusing only on those basic aspects without the burden of game engine features/concepts may lead to quicker improvement in your overall coding skills.
Zini I understand that aspect of boolean, but the question is what makes it become invisible again? If you set visible = true, won't it just stay true?
xyz That is a good suggestion. The issue is I struggle learning when I don't have a concrete objective, and I have yet to find a programming course that does that. Also I tend to learn better by doing/seeing the results than just taking a course. But, I'll do some research to see if I can find a foundational Python course.
xRegnarokx My code does set visible to false, if active is false. But @DaveTheCoder has a point. It doesn't handle the case when the array becomes empty.
xRegnarokx Imho, most good courses are task oriented. I tend to recommend Automate the Boring Stuff with Python.. It's a free online book. Check it out and see if it suits your learning style.
xyz I'm interested on good tutorials in python as well! "automate the boring stuff with python" proceeds to not automate any boring task, and basically teach python syntax as usual. I'm interested on finding a good hands-on teaching python courses for our juniors, I did a quick search last year but was left unconvinced. Does anybody have some gold tutorials in mind? Maybe my expectations are unrealistic.
I love the way tiangolo documents for example. And fowler is another icon.
- Edited
quimnuss I'm interested on good tutorials in python as well! "automate the boring stuff with python" proceeds to not automate any boring task, and basically teach python syntax as usual.
It's full of practical examples and the second half is literally just projects that automate boring tasks, but it's a book not a tutorial. The majority preference for "quick and easy" tutorials is precisely what got as where we are - a lot of people lacking the most fundamental knowledge while attempting to execute relatively ambitious projects.
There's an ages old wisdom. If you want to learn something proper - read a book about it. It takes time but it works