Why do things in set()?

It seems to be a lot of the things we’re doing here would make more sense in the take_damage() function… whereas the set() functions seems like it’s a convenient but less correct way to do stuff? I feel like setting a bunch of stuff in the set function would feel a bit lazy and let me get away with some indisciplined stuff? Not to mention harder to trace/debug?

Perhaps I’m just not clicking with the set function enough yet… I’m still not sure what “health_in” is, where it’s coming from, or going… or how it knows something has changed or not… since it’s not in the process function, etc. I guess I am confused on this one!

Hi Bill,

This is a teaching point on how to use setters and getters. If you remember from the previous lecture (Introducing Properties) we are declaring a variable called current_health which is an int and then we are setting another variable called health_in.
We are then setting the current_health to the health_in value that is being passed in, You have to remember that health_in is just the variable we are using here and it may not be named the same as long as its an int being passed in then the code does not care what they are called. The code only actually cares if we are passing in more than one type of variable and then they have to be defined in the right order (IE if we pass in an int and then a float then the method has to expect an int and THEN a float not a float then and int but thats digressing a little from the understanding)

We use the set function a little more later on for gold and such so it will probably become more clear later on in the course

2 Likes

Thanks Mark! I am going to go back and review the previous lecture, I think I just have a basic disconnect there and want to get it shored up before I get too far past it!

1 Like

Diving into why we use set() is really cool. It’s great for getting rid of any repeats in a list and can make some tasks way easier. Plus, the way you’re diving into understanding these GDScript concepts is impressive.

1 Like

If I may throw this remark in, just to make sure confusion is avoided: We are using GDScript here, not Python. Despite some similarities they are separate languages.

1 Like

Yes, you are correct. I must have confused this thread with a thread on another forum. You see, I also work in Python as well, so that’s why it came up that way.

1 Like

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.

Privacy & Terms