Title here
Summary here
Here’s a function that will take an arbitrary number of int
s as arguments.
void sum(array<int> nums) {
for (uint i = 0; i < nums.length(); i++) {
print(nums[i] + " ");
}
int total = 0;
for (uint i = 0; i < nums.length(); i++) {
total += nums[i];
}
print(total + "\n");
}
void main() {
// Variadic functions can be called in the usual way with individual arguments.
sum({1, 2});
sum({1, 2, 3});
// If you already have multiple args in an array, apply them to a variadic function using func(array).
array<int> nums = {1, 2, 3, 4};
sum(nums);
}
To run this AngelScript code:
.as
file.Now that you know how to use variadic functions in AngelScript, let’s delve into more advanced features of the language.