printf VEX function

Prints values to the console which started the VEX program.

Contexts: image3d, chop, cop, pop, sop, surface, displace, fog, light, shadow, photon, cvex

  1. void printf(string format)

Prints values to the console which started the VEX program.

The format string is a simpler version of the C printf format string. When a % symbol is found in the string, an argument will be printed out in a format specified by the characters following the % symbol. The conversion of the argument is specified by a single letter: g, f, s, d, x, c, p.

You can prefex the format option with an optional width specification. You can also use * instead of a width to specify that the width should be read from the next argument. If the width starts with 0, the argument will be printed with leading 0s instead of leading spaces.

%g, %p, %c

Print an integer float, vector, vector4, matrix3, matrix or string in “general” form.

%f

Print a float, vector, vector4, matrix3 or matrix in floating point form.

%s

Print a string.

%d

Print an integer variable in decimal.

%x

Print an integer variable in hexidecimal.

%%

Print a percent sign (%).

There is no support for special operators on output formatting (for example dash, dollar, or dot).

Examples:

printf("P = %g, dot(N, P) = %g, %d = %x\n", P, dot(N, P), ptnum, ptnum);
printf("RGB = {%g,%g,%g}\n", clr.r, clr.g, clr.b);
printf("P = %20s\n", "20 chars");
Cf = texture(sprintf("/maps/map%d.rat", i));
Cf = texture(sprintf("/maps/map%04d.rat", i));