void function(text, ...)

Non-platform specific questions.

void function(text, ...)

Postby Hblade » Thu Apr 05, 2012 4:16 pm

How would I make this work? I want to be able to display variables in a command that creates a text actor, but for some reason, when I do this, it always ends up as 392 O-o no matter what, even if you set it to 94 lol
Code: Select all
function("variable: %d", var);


or:
Code: Select all
function("variables: %d-%d", xscreen, yscreen);


So how would I get this to work?
Subscribe to my YouTube? - Yes| No
User avatar
Hblade
 
Posts: 4455
Joined: Fri Dec 08, 2006 11:14 pm
Score: 181 Give a positive score

Re: void function(text, ...)

Postby skydereign » Thu Apr 05, 2012 7:56 pm

So you are just writing a wrapper function to sprintf? Make sure the char* you specify is a const char*.
Code: Select all
void
function (const char* format, int xs, int ys)
{
    sprintf(text, format, xs, ys);
}

But not sure why you would even do this, because you already know what format you want (at least the part that involves the integers you pass it). So the same function can be accomplished like this.
Code: Select all
sprintf(text, "variables: %d-%d", xscreen, yscreen);
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: void function(text, ...)

Postby Hblade » Thu Apr 05, 2012 8:43 pm

I've worked around it using text variables. The command is:
Code: Select all
createWindow("text_actor_to_display", "message", x,y,width,height, index);


Check game demos to see what I mean. But now its all better.
Subscribe to my YouTube? - Yes| No
User avatar
Hblade
 
Posts: 4455
Joined: Fri Dec 08, 2006 11:14 pm
Score: 181 Give a positive score

Re: void function(text, ...)

Postby tintran » Thu Apr 05, 2012 9:01 pm

I think Hblade is trying to use something like
http://www.thinkage.ca/english/gcos/expl/c/incl/stdarg.html
like a function that will accept an optional list of parameters like sprintf right?
I tried looking into this but there's no way to include <stdarg.h> so i can't even play around with functions va_start, va_arg, va_end.
User avatar
tintran
 
Posts: 157
Joined: Fri Dec 24, 2010 1:34 am
Score: 30 Give a positive score

Re: void function(text, ...)

Postby skydereign » Thu Apr 05, 2012 9:06 pm

It looked like he might be, but as you've noted gE doesn't support argument lists so it would be better just to call a function that can handle it (his function looks just like sprintf without the text).
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: void function(text, ...)

Postby lcl » Thu Apr 05, 2012 9:29 pm

Hblade, the easiest way to go is to create a local string for that, a string that only is there in the event you call the function and only the frame you call the function. You can do it like this:
Code: Select all
char myTemporaryString[256];
sprintf(myTemporaryString, "Variable: %i\nMy string: %s", someIntVar, someString);
//And then just input the 'myTemporaryString' into your function,
//to the place where you want the text to be, like:
myFunction(myTemporaryString, ...other arguments of the function...);

So you see that there's actually no need for the thing you want. =D

(Of course, I don't recommend using namemonsters like 'myTemporaryString' ... XD)
User avatar
lcl
 
Posts: 2339
Joined: Thu Mar 25, 2010 5:55 pm
Location: Finland
Score: 276 Give a positive score


Return to General

Who is online

Users browsing this forum: No registered users and 1 guest