+7 votes

Is just something I was always curious about, what is the use of the "PASS" keyword, if in GDscript you can return void by simply calling return and nothing else? Is "PASS" related to threading or something like that?

in Engine by (304 points)

if im not mistaken pass simply means you ignore and sort of place a "block" of code that does nothing... you can use pass when writing a script with lots and lots of ifs and simply not wanting to implement all the ifs yet and you only write the ifs themselves down

1 Answer

+21 votes
Best answer

pass does nothing but it prevents error from empty function or any syntax requires indented line.

for example

func my_func1(): # error if no function body

func my_func2(): # no error but just empty function
   pass # does nothing, but can do it later

func my_func3():
   for i in range(10):  # error if no statements for "for" loop
       pass # no error if "pass" syntax is here when no statements

func my_func4():
   pass # does nothing
   var x = 1 # this code executes

func my_func5():
   return # quit function
   var x = 1 # this code does not execute
by (9,742 points)
selected by

OOOOooh I see, I always thought it "returned" empty because I always used as the last line of the function. What it actually does is nothing, hahaha.


pass is useful for breakpoints too.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.