Function Not Being Called And Returns Null Immediately Seemingly At Random

Godot Version

4.3

Question

I have a script I am working on which includes an encryption script being called, this script is held inside an autoloaded-scene. So to start I try calling a function to test and get it returning null without calling the function - I know if isn’t calling since the first line of the function prints to the console and nothing was printed - and the same happens with another function I call prior.

So I comment that code out and make another function inside this script, called ‘testing’. All this function does is print ‘I was called!’ to the terminal, call it above my commented-out code, it works. I add the the second function I called earlier and it calls perfectly fine, so delete that code and un-comment out my old test. I run it; same result as before.

I am genuinely stumped here, any help would be greatly appreciated.

–Main Script (Works; Other script prints everything)–

EncryptionManager.call_deferred("testing")
EncryptionManager.call_deferred("set_alphabet")

–Main Script (Doesn’t Work; Other script doesn’t seem to call, as nothing is printed and no values changed (alphabet starts as an empty Array, this results in it crashing as test1 can’t be set to returned ‘null’ as it is a String)–

EncryptionManager.call_deferred("set_alphabet")
print(str(EncryptionManager.alphabet))
var test1 : String
test1 = EncryptionManager.call_deferred("main", "Hello World!", "+")
test1 = EncryptionManager.call_deferred("main", test1, "-")
print(test1)

–Other Script–

func testing() -> void:
	print("I was called!")
	return

func set_alphabet() -> void:
	print("i was called?")
	alphabet = ["a", "b", "c"]
	print("alphabet: " + str(alphabet))
	return

func main(input: String, new_mode : String) -> String:
	print("input: " + input + ", mode: " + new_mode)
	return input

I am totally confused by the question but these lines will never work as call_deferred always returns null.
From the docs:

Calls the method on the object during idle time. Always returns null, not the method’s result.

2 Likes

Thank you! Sorry about the question not being clear, I hardly understood the problem which didn’t help. But I never knew about call_deferred not returning values, which helped with the second part about setting the variable, I was able to substitute it for callv(). And with the first part about ‘set_alphabet’ it just seemed to fix itself somehow after adding some delays to make sure the alphabet it set before the main function is called.

Thanks for the help!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.