What does callv() do?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Matt_UV
:warning: Old Version Published before Godot 3 was released.

I don’t really understand what the callv() func does.
Variant callv( String method, Array arg_array )

I know it calls a function of my object, but it doesn’t seem to work all the time…

For instance :

[...]
func get_minimum(a,b):
   return min(a,b)

func _ready():
   print(callv("get_minimum",[2,3]))

I get

2

But if I try to call the built in function min via a callv, I get nothing

func _ready():
   print(callv("min",[2,3]))

Thanks for you help!

:bust_in_silhouette: Reply From: avencherus

callv(), much like call_deferred() are functions that exist on the Object class, and deal with calling functions that belong to that object.

In this case it might help to understand if you imagine your code as self.callv()

It only has access to functions in the caller class. The purpose of it is to call a function by a string. So you might want to call a function on another object, like other_object.callv(“other_func”, 1)

So this will not work on anything other than functions that belong to the caller object making the call. As you said, min() is a built-in, so it’s not part of your object.

Thanks for your answer! That’s what I was afraid of… too bad, I will have to find another way! :slight_smile:

So, if I understand well, the only difference between call() and callv() is the number of possible arguments and the syntax?

Matt_UV | 2017-02-05 16:04

Your work around of minimum() is likely fine.

As for what they do, they both return variant results, and it does seem the differences are in the parameter signature. One is comma separated arguments and the other is an array of arguments.

https://github.com/godotengine/godot/blob/3890256fc57eafb2db83d328b8caf772188e21d4/core/object.cpp#L773

avencherus | 2017-02-05 18:59