Formatted string problem

You must understand the Game Editor concepts, before post here.

Formatted string problem

Postby SuperSonic » Mon May 28, 2012 7:12 pm

Hey guys! I have a deep question. I wanted to create my own version of the openUrl() function. Mine was supposed to do the same thing except that it would take in a formatted string like sprintf(). Here's the function I made:
Code: Select all
void url(const char *__format, ...)
{
    openUrl(__format);
}
Now of course, this deosn't work. Can anyone tell me how to fix it? A point will be your reward :)

Thanks!
SuperSonic
A tree never hits an automobile except in self-defence.

Want to use your joystick or controller with Game Editor? Check out my controller engine =D
User avatar
SuperSonic
 
Posts: 1443
Joined: Fri Sep 24, 2010 9:24 pm
Location: Anywhere
Score: 72 Give a positive score

Re: Formatted string problem

Postby Hblade » Mon May 28, 2012 7:16 pm

just define it :D Like this maybe
Code: Select all
#define url openUrl


To use:
Code: Select all
url("url here");


it wont turn yeller' though.
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: Formatted string problem

Postby SuperSonic » Mon May 28, 2012 7:19 pm

Haha, that's not exactly what I mean. I want it so that I can do this:
Code: Select all
url("www.%s.com", "game-editor");
:D
A tree never hits an automobile except in self-defence.

Want to use your joystick or controller with Game Editor? Check out my controller engine =D
User avatar
SuperSonic
 
Posts: 1443
Joined: Fri Sep 24, 2010 9:24 pm
Location: Anywhere
Score: 72 Give a positive score

Re: Formatted string problem

Postby Hblade » Mon May 28, 2012 7:42 pm

oh xD I get it. Quite simple actually. First create 2 variables, each char variables. named:

wName, fType

Now do this:
Code: Select all
void setWeb(char*webName, char*formatType)
{
    sprintf(wName, webName);
    sprintf(fType, formatType);
}



now you can do your function:
....

OH WAIT.. I see what you mean now!... nvm that is hard xD
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: Formatted string problem

Postby SuperSonic » Mon May 28, 2012 7:52 pm

Hblade wrote:OH WAIT.. I see what you mean now!... nvm that is hard xD
:lol:

Yeah, I know. But it would be so useful. Know what I mean? :D
A tree never hits an automobile except in self-defence.

Want to use your joystick or controller with Game Editor? Check out my controller engine =D
User avatar
SuperSonic
 
Posts: 1443
Joined: Fri Sep 24, 2010 9:24 pm
Location: Anywhere
Score: 72 Give a positive score

Re: Formatted string problem

Postby Hblade » Mon May 28, 2012 8:13 pm

yeah it could :D
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: Formatted string problem

Postby skydereign » Mon May 28, 2012 8:49 pm

Well, in that case it doesn't seem too necessary. As you would just use the sprintf beforehand. But, if you just wanted to be able to write custom urls with it, you could do something like this.
Code: Select all
void
url (char* first, char* second, char* third)
{
    char buffer[30];
    sprintf(buffer, "%s.%s.%s", first, second, third);
    openUrl(buffer);
}


The thing is in gE we can't use argument lists. The ellipse operator is supported, but you can't use the varg functions.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: Formatted string problem

Postby SuperSonic » Tue May 29, 2012 3:59 am

skydereign wrote:The thing is in gE we can't use argument lists. The ellipse operator is supported, but you can't use the varg functions.
Aww, that's too bad :(

But I know I can do something like this in pure c++. Could you send me a pm how to do it? (if you have time) :P
A tree never hits an automobile except in self-defence.

Want to use your joystick or controller with Game Editor? Check out my controller engine =D
User avatar
SuperSonic
 
Posts: 1443
Joined: Fri Sep 24, 2010 9:24 pm
Location: Anywhere
Score: 72 Give a positive score


Return to Advanced Topics

Who is online

Users browsing this forum: No registered users and 1 guest

cron