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

Definition of virtual, const and vararg function classifications in the docs #1753

Closed
wyattbiker opened this issue Sep 20, 2018 · 3 comments · Fixed by godotengine/godot#40872

Comments

@wyattbiker
Copy link

In the API docs, e.g. http://docs.godotengine.org/en/3.0/classes/class_node.html you see functions classified as virtual, const and vararg. I am trying to understand what that means with respect to the functions.

So I am guessing virtual classification is similar to abstract, and must be defined in your code (E.g. callbacks). But const or vararg classification I am not so sure. What does this classification mean?

Examples.

void    _ready ( ) virtual
Node    get_child ( int idx ) const
Variant rpc ( String method ) vararg
@LikeLakers2
Copy link

LikeLakers2 commented Sep 20, 2018

From what I can tell:

  • virtual means that's a function for a event. The function is supposed to be defined in your own code, with your own code. For example, if you want some code to run when the node is ready, you would define _ready() with that code; If you want to run code whenever there is input from a controller, mouse, or keyboard, you would define _input(event); and so on. If not defined, these typically do nothing.

  • const seems to mean that the function, given the same arguments and same context every time, will always return the same value. For example, get_child(5) will always return the child at index 5, assuming that no child nodes are ever removed. get_parent() will always return the same parent, assuming the node hasn't been moved to another parent in the scene tree. And so on. (I may be wrong on this, but this is what I always understood about const)

  • vararg means that the method can accept any number of arguments (including no arguments) after the ones explicitly shown. For example, print() is a vararg function, which means you can pass more than one argument to it and it will react accordingly. In the case of print(), it will just print the arguments in order, on the same line. print('a', 'c', 'b') will print acb.

@vnen
Copy link
Member

vnen commented Sep 21, 2018

const actually means that the function has no side-effect, i.e. it won't change any property of the object when called.

@wyattbiker
Copy link
Author

Thanks for the explanations which make sense. It does need to be explained in the docs (unless it is described some place and I did not find it) because I know i asked elsewhere and I had differing answers.

Calinou added a commit to Calinou/godot that referenced this issue Jul 30, 2020
akien-mga pushed a commit to godotengine/godot that referenced this issue Jul 30, 2020
MarcusElg pushed a commit to MarcusElg/godot that referenced this issue Oct 19, 2020
huhund pushed a commit to huhund/godot that referenced this issue Nov 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants