Script Doubt

1 view
Skip to first unread message

Natalie Omahony

unread,
Aug 5, 2024, 4:58:05 AM8/5/24
to grevperreta
NoteThis American Life is produced for the ear and designed to be heard. If you are able, we strongly encourage you to listen to the audio, which includes emotion and emphasis that's not on the page. Transcripts are generated using a combination of speech recognition software and human transcribers, and may contain errors. Please check the corresponding audio before quoting in print. PrologueIra GlassFrom WBEZ Chicago, it's This American Life. I'm Ira Glass. And I want to tell you about two police investigations. One of them is done so inspiringly well, it's like the detectives in it are like detectives on a television show-- smart and resourceful and great judgment and just police at their very best. The other case-- the same crime, lots of the same facts-- is the opposite. It goes terribly.

What I want to know is that whether something like this will work or not ? And if yes then I want to know if the code in the child script will behave differently as the grandchild script is making changes to variables and is inheriting from child script.


The changes I made to the variables should work. And strangely the rotate_speed is the only variable that is getting changed. The rest are showing no change. What I mean is that when I instance these two scenes with different scripts in the main scene, they are still acting in same way apart from their rotation.


Okay guys. I just have a question to ask because I am confused about how you have to interpret "scenes" and "scripts": how come on this page : _practices/what_are_godot_classes.html , it says this: "Still, many best practices using Godot involve applying object-oriented programming principles to the scripts and scenes that compose your game. That is why it's useful to understand how we can think of them as classes." , but after all always on the same page it says at the beginning that "scenes" and "scripts" are not technically "classes" ??I just can't understand how I am supposed to interpret the scenes and scripts, or if I have misunderstood the meaning of what I read, can anyone clarify it for me?


We must distinguish between the representation of data and that of programming logic, and what's inheritance and what is composition. A lower node in a tree of inheritance inherits from the upper levels, but can additionally (or replacing) have other traits. See a script like an object being attached to a node in the SceneTree, but not inheriting from the node itself. Or, more abstract, a representation of the behaviour of an object in the scene tree.


In OOP the ability to store a script can for example be realized by storing what's called a pointer to a data structure representing the script, or even to a chain of such structures. This ability itself can be inherited from the root all the way down, but what is actually connected to this pointer (or whatever method is chosen) can differ.


Like you can have dad being a merry fellow with a blue hat and yellow boots (hello Tom) and his son being more down to earth wearing sandals and a baseball cap :-). Yet still both are humans and one inherited from the other, with different scripts attached for mood and clothing. They even can change their scripts, by changing their minds, but they can not escape the tree of inheritance. Same with OOP inheritance and composition.


For example, you are a human (a class) who can put on hiking gear and become a 'hiker'. As such you have some boots, and a tent, and a camping stove etc. So while you can think of yourself as hiker as a class, the script is only an adornment on an instance: A hiking 'script' could also be attached to a humanoid robot and it too could have all the attributes of a hiker and here we note that a Hiker could be-a human or could also be-a robot.


Because GD script is duck taped, binding a script to a node is only really constrained by the base type it can be bound to (ie extends Object, Node or Node2D). Scripts can be bound to any sub-class node of the one its (root-base) script extends.


A class is just a thing. For example, an animal is a class of living beings. And a cat is a type of animal, it is also a class of beings, and a child of animal. A car is a class, as a type of vehicle. A plane is also a class, as is a tank, and they are both types of vehicles. In fact, almost anything can be a class, if it has a name and represents something. Food can be a class, sushi (inherits from food), pizza is a class. Basically whatever you want.


Right, Godot is not exactly real OOP, so you don't have to bother learning what it really means (and it takes years to actually understand OOP). The only thing Godot uses is basically classes and inheritance. A class is any type of thing (which is basically any concept that can be named). And other classes can inherit from that class, as a specialized type of thing. That's all you need to know.


cybereality Ok guys what I understood in all this talk is that as cybereality wrote : Godot is not purely a software that "stores" OOP, but that it only makes use of "classes" and "of inheritance" and these two concepts in Godot are not completely related to pure OOP as for example "Java". If I am wrong please correct me.


@Byl : I'd say just play around with the editor, plant nodes, set them in a meaningful order, attach scripts to make them jump around or whatever, you get a feeling of how things work together. And it actually doesn't matter if that's an ECS whith components stitched together below or an OO-approach with a scene-tree of nodes and inheritance and sideways attached scripts.


If we take a look at unity there are objects placed and then components attached, while in Godot there are nodes placed in a hierarchy. Both, components and nodes still need tweaking of a bunch of parameters, but the basic structure between the two approaches is somewhat different. But let's shrug that off and make games :-)


So OOP can fill entire books. But there are 4 main tenets. Inheritance, encapsulation, abstraction, and polymorphism. Inheritance is just the use of classes and objects, which can have bases and children, which Godot supports. Godot also supports polymorphism in some limited sense, in that child classes can override methods in base classes (though in a language like C++ or Java you can do more). However encapsulation and abstraction are totally missing in GDScript (though I guess could be used in C#, I haven't used it much). This is where you can define interfaces or custom APIs for your object, such as with public methods. Languages like C++ have everything private by default, meaning objects cannot access properties of other objects without permission. This is very useful for organization and design, and keeps code cleaner. It is not 100% needed, you can write games without it, but it helps with more complex design. But, to be honest, people have been moving away from OOP in games in particular, because you end up wasting time designing things that aren't necessary. So with game scripting it is not the end of the world, and you end up writing games faster without OOP. And you don't even have to learn it to make a game. Especially for simple games, just using inheritance may be enough. Only if you were writing like The Sims or something, you would need a complex design.


cybereality So you're saying that for simple games you don't need to learn OOP, whereas you do for more complex games. But another doubt arises for me that is : shouldn't the more complex games from the way you described it, have let's say the same "structure" as the simpler games? I mean, without using OOP?


Byl So you're saying that for simple games you don't need to learn OOP, whereas you do for more complex games. But another doubt arises for me that is : shouldn't the more complex games from the way you described it, have let's say the same "structure" as the simpler games? I mean, without using OOP?


An analogy is building a dog house versus building a mansion. In the former case you can start nailing boards together without any planning and probably wind up with a reasonably acceptable result. In the latter case, you'd have a mess.


Btw., before diving in such design patterns they need to learn and have some experience with C++. C++17 and on doesn't need many of these patterns any more, some of them being just crutches and others as trivial as a main loop. They were never set in stone, and they may be outdated by now.


And I rode that energy forward enough to make some bold decisions, buying $40,000 worth of camera equipment (while having literally no clue what most of it actually did!), putting together an amazing team of dedicated people, and setting off on this adventure.


These moments, these subtle (and sometimes not so subtle) voices of doubt are the difference between feeling unfulfilled, letting your dreams fade away, and living a life of fulfillment, passion, contribution, and joy!


Hi Nick,

Thank you. I am learning how to manage with an ageing husband who I suspect has dementia. I am learning how to release the feelings of fear and panic and loss and grief that are my current companions. This meditation feels heaven sent.

Thank you.

Jane


Thank you for this very insightful meditation. It is VERY helpful in calming those pervasive, recurring feelings of doubt. Being able to modify it to fit the issues creating the doubt is of great benefit. I will use it a lot. Thanks again!


Feeling of release. Connect to rhythm through tapping, helps me to tune in to the clanging sounds of doubt, and how they do not fit in. I feel the feelings of doubt as a covering from head through my chest. Tapping, I visualize the iron cloth of doubt laid over me turn to butterflies and are released.


Thank you once again Nick Tapping has become a way of life for me. I do tapping every day and I believe it will be the answer to my health problem. At times doubt does creep in so thank you once again Lyn


I think just taking the time and having someone there with me to do this has unleashed all this emotion. I have always felt totally alone. I find your voice very soothing. I love how Tapping accesses deep emotional levels as well as clearing them.

Thanks Nick

3a8082e126
Reply all
Reply to author
Forward
0 new messages