Passing a formatted string into a file loading method

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
sunnystormy
Posts: 105
Joined: Mon Jun 02, 2014 2:32 am
Location: Washington, D.C.
Contact:

Passing a formatted string into a file loading method

Post by sunnystormy »

Hello! I'm new to Irrlicht, and eager to adhere to DRY, so I don't want to have to type long strings multiple times.

I did this:

Code: Select all

const char *filePath = "/usr/include/irrlicht-1.8.1/media";
At the top of my main file for the "Hello World" Irrlicht tutorial.

And this:

Code: Select all

IAnimatedMesh *mesh = smgr->getMesh(stringc("%s/sydney.md2", filePath));
Is as far as I've gotten in trying to make that idea work.

Any advice on how to configure the string so I can properly load the file and reuse the path whenever I need to? Thanks!
My blog: http://fsgdp.wordpress.com "The Free Software Game Development Pipeline"
mongoose7
Posts: 1227
Joined: Wed Apr 06, 2011 12:13 pm

Re: Passing a formatted string into a file loading method

Post by mongoose7 »

I don't understand what is going on here. Printf returns a number, not a pointer to a string. In fact, I think "45" *is* the file name.

Err, I see you removed the weird error message, so now I do know what is going on - you are trying to open the file "45".
sunnystormy
Posts: 105
Joined: Mon Jun 02, 2014 2:32 am
Location: Washington, D.C.
Contact:

Re: Passing a formatted string into a file loading method

Post by sunnystormy »

Edited my original post. The line number shouldn't have been included in the message. I'm trying to pass a formatted string as an argument into the "getMesh" method so I can dynamically load content without having to type in the file's path repeatedly.
My blog: http://fsgdp.wordpress.com "The Free Software Game Development Pipeline"
mongoose7
Posts: 1227
Joined: Wed Apr 06, 2011 12:13 pm

Re: Passing a formatted string into a file loading method

Post by mongoose7 »

The traditional way is to use sprintf. Or you can use a #define:

smgr->getMesh( MEDIA "sydney.md2" );
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Re: Passing a formatted string into a file loading method

Post by hybrid »

Better use the Irrlicht filesystem approach and add your desired filepath as a mounted directory. That way you can avoid the prefixed path and directly access from within that path as if you changed to the path.
The latter would also work, i.e. change your working directory to whereever you want to load from and call the filename directly.
sunnystormy
Posts: 105
Joined: Mon Jun 02, 2014 2:32 am
Location: Washington, D.C.
Contact:

Re: Passing a formatted string into a file loading method

Post by sunnystormy »

Hey, Hybrid, would you mind elaborating on this a little bit? I don't believe I've ever used a "mounted directory" before...

Thanks!
My blog: http://fsgdp.wordpress.com "The Free Software Game Development Pipeline"
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Re: Passing a formatted string into a file loading method

Post by hybrid »

It's in the examples, at least in the more complex ones (q3 explorer, demo). You basically define a path to become a new "zip file" or similar using device->getFileSystem()->addFileArchive("../../media/"); or whatever path you use.
Post Reply