1
\$\begingroup\$

I tried this:

godot::String str = "values: %f,%f";
double a = 1.0;
double b = 2.0;
str = str % a % b;

Result string is:

"not all arguments converted during string formatting"

Documentation completely ignores that C++ exists and suggests the following GDScript:

var format_string = "%s was reluctant to learn %s, but now he enjoys it."
var actual_string = format_string % ["Estragon", "GDScript"]

print(actual_string)

The equivalent of this in C++ would be:

str = str % std::tuple(a, b);

But there is no operator for std tuple.

How can I format multiple values into godot string?

\$\endgroup\$
0

1 Answer 1

2
\$\begingroup\$

According to the source code, godot::String does not seem to implement % overloading: char_string.hpp.

The common_engine_methods_and_macros documentation shows some common methods, including methods for formatting strings:

vformat(String("values:%f,%f"), 1.0, 2.0);

godot:String also implements a format method that accepts a godot:Array parameter:

String("values:{0},{1}").format(Array::make(1.0, 2.0));
\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .