All Questions

Community

S
nodeg
posted to: Creating the Unit

A couple questions/comments

First my questions:

1. I'm not sure I'm following the _name variables.  At first I thought they were all pseudo-private like in functions, but _is_walking and is_selected both seem identical in scope, and both have setters. What is the significance of the underscore?

2. Why are we giving Unit it's own class_name?

Comments:

1. It doesn't give any direction on how to position the sprite and shadow, since by default they overlap.  I assume that the sprite is moved up to be centered in the shadow?

Feedback:
1. I really like the structure of the unit and the implementation of a grid using a .tres.  I've done most of my games to date using grids and I never thought of that.  
2. I've learned at least 3 cool things that I'll use regularly just from the last two lessons.  Very impressed by the course so far.

  • Nathan Lovato replied

    Here are the answers to your questions:

    1. Yes, variables with a leading underscores are pseudo-private. Here, is_selected is intended to be modified from another script, to make the character blink.

    The purpose of _is_walking is different: we only use it inside the unit script, mostly to turn processing on and off.

    As it is pseudo-private, it won't be used from the outside. Notice how the setter function is also pseudo-private, with its leading underscore.

    Here, we could just turn processing on and off. I only added to named variable to make it a bit more explicit as to what toggling processing means in this case. It's one of those bits of code that are really for teaching purposes more so than anything.

    2. Why not? I think you can go ahead and give class names to many scripts in your Godot games, be it only to ensure that you keep your classes unique and your style consistent. At least for all the scripts that make your games foundations.

    For things like scripted events that are specific to one level, you probably would rather want to use an in-line script.

    You'll get to use the class name for type checks in an upcoming lesson.

    Regarding your comment, yes, you will want to move the units right up and center it on the shadow. There are some things like these we don't mention explicitly in this course (we only show them in pictures) because it's intended for people who are already comfortable with Godot.

    Thank you very much for the feedback, I'm glad you're learning some new things in the course!