Page 2 of 2

Re: Code won't work...

PostPosted: Sat Feb 25, 2012 8:48 pm
by skydereign
printf is kind of like puts, though a tad more complex. gE doesn't have printf since there is no standard out to print to. But instead you can use the sprintf and fprintf functions (one prints into a string, the other into a file). With puts you just have to have a chain of the things you want to print, but with the printf functions you have to declare a format (though it's pretty handy). The format is the constant string in the double quotes. You can use % as a way of inputting variables into the string.
Code: Select all
sprintf(text, "some text"); // this would set the actor's text to 'some text'
sprintf(text, "var = %d", var); // displays what var is equal to

If you want to display different variable types you need to use different characters. %d and %i mean integers, %lf for doubles, %s is for strings, %c is for a character, and %p for a pointer. There are a few more but those are the basics. You pass all of the variables you want into the string after the format (in the order the % comes in).
Code: Select all
sprintf(text, "integer: %d\nstring: %s\ncharacter: %c", int_var, string_var, char_var);

Re: Code won't work...

PostPosted: Sun Feb 26, 2012 1:48 am
by ResourceDragon
Ok. Thanks for the info. :D


Solved.