Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | WuaUP |
I’m good at C#, but I’m a rookie at Godot.
I want to do complex logic, so I will use a lot more C# in Godot.
I wish I could do some things in GDScript, but I’m ignorant.
In C# I can define a parent class and a daughter class that inherits from the parent.
I have the instructions “new” and “override” to specify the form of the inheritance. This is powerful.
In the son, with “override” I say it is compatible with the past.
With “new” I say that it is incompatible with the past, and that it uses the previous method of the father.
For example,
father fatherObject = new son ()
fatherObject is a parent object that uses a son object.
The way to use it will depend on the implementation of the methods, that is to say if when defining them in the son, “new” “override” is used in the methods or variables.
fatherObject will invoke the methods defined in the father if “new” is defined
fatherObject will invoke the methods defined in the child if they are found to be “override”
How is this done in GDScript?
Any link that explains it? I have not found. Thank you
Please, I need the translation of this code from C # to CDScript. Thanks for the answers!
// Example code in C#:
class A {
public virtual int Hello() {
return 1;
}
}
class B : A {
new public int Hello(object newParam) {
return 2;
}
}
class C : A {
public override int Hello() {
return 3;
}
}
A objectA;
B objectB = new B();
C objectC = new C();
Console.WriteLine(objectB.Hello(null)); // 2
Console.WriteLine(objectC.Hello()); // 3
objectA = objectB;
Console.WriteLine(objectA.Hello()); // 1
objectA = objectC;
Console.WriteLine(objectA.Hello()); // 3
/////////////////////////////////////////
WuaUP | 2018-05-28 18:22