Godot Version
4.2.1
Question
I want to make a function:
update_control(type, updater, ...other_args)
But i don’t know how to make length of arguments variable.
I tried ...name
name...
*name
and it caused errors.
4.2.1
I want to make a function:
update_control(type, updater, ...other_args)
But i don’t know how to make length of arguments variable.
I tried ...name
name...
*name
and it caused errors.
It’s not currently possible. You could use an Array
or Dictionary
for the rest of the arguments.
In Godot, you can use an array or a dictionary to handle variable-length arguments if you want to pass multiple arguments to a function without specifying them explicitly. Here’s an example of how you can achieve this:
func update_control(type, updater, other_args=):
# ‘other_args’ is an array that can hold any number of additional arguments
# You can use it as needed in your function
# Example: Print the type and updater
print("Type:", type)
print("Updater:", updater)
# Example: Loop through other_args
for arg in other_args:
print("Other Arg:", arg)
update_control(“example_type”, “example_updater”, “arg1”, “arg2”, “arg3”)
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.