Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GDScript : Calling another static function inside a static function from a script calls its parent script's function instead of its own script's. #59280

Closed
rambda opened this issue Mar 18, 2022 · 1 comment

Comments

@rambda
Copy link

rambda commented Mar 18, 2022

Godot version

3.5 beta2

System information

Windows 10

Issue description

In GDScript, when calling a static funtion from a script, or an instance of this script, which extends a parent script, you call the function from its * own * script, (instead of its parent script).

So in GDScript, static functions are polymorphic.

Similarly, when calling a static function from an instance of the script, if this static function func_a calls another static function func_b, func_a will call func_b from its * own * script , (instead of its parent script), too.

However, when calling the same static function from the script (instead of an instance), func_a will call the function func_b from its * parent * script, (rather than from its own script).

It doesn't seem quite consistent.

Steps to reproduce

tool
extends EditorScript

class Person:

	static func get_breath_skill_level():
		return 0

	static func get_pitch_accuracy():
		return 1

	static func get_sing_skill_level():
		return get_breath_skill_level() + get_pitch_accuracy()

	func breath():
		print("breath ordinarily,")

	func sing():
		breath()
		print("and sing.")


class Singer:
	extends Person

	static func get_breath_skill_level():
		return 5

	static func get_pitch_accuracy():
		return 5

	func breath():
		print("breath professionally,")



func _run():
	var singer_1 := Singer.new()
	singer_1.sing() # can breath professionally
	print("singer_1's sing skill level == ", singer_1.get_breath_skill_level()) # prints 5
	print("singer_1's sing skill level == ", singer_1.get_sing_skill_level()) # prints 10
	print("Singer's breath level == ", Singer.get_breath_skill_level()) # prints 5
	print("Singer's sing level == ", Singer.get_sing_skill_level()) # prints 1

Minimal reproduction project

No response

@Calinou Calinou added this to the 3.5 milestone Mar 18, 2022
@lawnjelly lawnjelly modified the milestones: 3.5, 3.x Mar 9, 2024
@AThousandShips
Copy link
Member

AThousandShips commented Jun 4, 2024

Thank you for reporting, consolidating in:

It has more information

See there for more details, if you think something was missed about this and it's not the same issue, please comment here and it can be reopened

@AThousandShips AThousandShips closed this as not planned Won't fix, can't repro, duplicate, stale Jun 4, 2024
@AThousandShips AThousandShips removed this from the 3.x milestone Jun 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants