Code won't work...

Non-platform specific questions.

Re: Code won't work...

Postby skydereign » Sat Feb 25, 2012 8:48 pm

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);
User avatar
Posts: 3513
Joined: Mon Jul 28, 2008 8:29 am
Score: 587 Give a positive score

Re: Code won't work...

Postby ResourceDragon » Sun Feb 26, 2012 1:48 am

Ok. Thanks for the info. :D

Posts: 39
Joined: Thu Feb 16, 2012 2:17 am
Score: 0 Give a positive score


Return to General

Who is online

Users browsing this forum: Google Adsense [Bot] and 1 guest