How to use IFileSystem (data type issue)

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
raistca
Posts: 15
Joined: Sat Mar 26, 2011 5:26 am

How to use IFileSystem (data type issue)

Post by raistca »

So I'm trying to set up a system for loading save games, so for starters I just want to have the program open up the saved text file, read it into a string variable line by line so I can handle the information. I set up a simple test for functionality to display the read in information, but I can't get it to work due to the mismatched type.

Anyways, this is what I'm working with right now:

Code: Select all

	IFileSystem* loadGame;
	IReadFile* gameSave = loadGame->createAndOpenFile("\Saves\SaveState.ssf");
	void *dataLocation;
	char temp = gameSave->read(dataLocation, 8);

then later for debugging:

	guienv->addStaticText(temp, rect<s32>(10,10,260,22), true);
But this causes a "no suitable conversion between type char and const wchar_t". This is super frustrating.
ChaiRuiPeng
Posts: 363
Joined: Thu Dec 16, 2010 8:50 pm
Location: Somewhere in the clouds.. drinking pink lemonade and sunshine..

Post by ChaiRuiPeng »

you should use the irrlicht define

Code: Select all

c8
wchar_t is a wide character, char is something else.[/code]
ent1ty wrote: success is a matter of concentration and desire
Butler Lampson wrote: all problems in Computer Science can be solved by another level of indirection
at a cost measure in computer resources ;)
polylux
Posts: 267
Joined: Thu Aug 27, 2009 12:39 pm
Location: EU

Post by polylux »

First off, the "read()" function returns a signed integer (s32), not char. Might wanna change that.
Next, "addStaticText()" takes a wchar_t* as input param, that causes your conversion error.

PLEASEPLEASEPLEASE use the API docs, some people have put a lot of effort into this for a reason! ;)
beer->setMotivationCallback(this);
raistca
Posts: 15
Joined: Sat Mar 26, 2011 5:26 am

Post by raistca »

ok so then how do I use read (or whatever else I need to use) to return a character or string?
polylux
Posts: 267
Joined: Thu Aug 27, 2009 12:39 pm
Location: EU

Post by polylux »

Easiest way:

Code: Select all

core::stringw retval = L"Bytes read: ";
retval += gameSave->read(dataLocation, 8);
guienv->addStaticText(retval.c_str(), rect<s32>(10,10,260,22), true);
In that style (might not be syntactically correct now).
beer->setMotivationCallback(this);
raistca
Posts: 15
Joined: Sat Mar 26, 2011 5:26 am

Post by raistca »

Ok cool, sorry I've been looking through the API but my brain has turned to mush where C++ is concerned (too much Java and PHP), so I sometimes have trouble making heads or tails of it.

Anyways, I'm implementing your suggestion, but for some reason I'm getting an unhandled exception, which seems to occur at the initialization of the IReadFile instance. Here's the code as it stands now:

Code: Select all

	IFileSystem* loadGame = 0;
	IReadFile* gameSave = loadGame->createAndOpenFile("\Saves\SaveState.txt");  //Exception seems to be happening here, am I using that right? (I did double check that the file exists)
	void *dataLocation;
	core::stringw retval = L"Bytes read: "; 
	retval += gameSave->read(dataLocation, 8); 

	guienv->addStaticText(retval.c_str(), rect<s32>(10,10,260,22), true);
Radikalizm
Posts: 1215
Joined: Tue Jan 09, 2007 7:03 pm
Location: Leuven, Belgium

Post by Radikalizm »

Your loadGame variable is a null pointer, this is what's causing your exception
You should use the filesystem created by irrlicht to create a readfile

It's a common issue for people moving from managed languages like java or C# to get familiar with pointers, if you're confused by this or if you're not sure how to use them please read up on them as fast as possible, pointers are essential to C++, so you can't really do without them
polylux
Posts: 267
Joined: Thu Aug 27, 2009 12:39 pm
Location: EU

Post by polylux »

Copy that.
beer->setMotivationCallback(this);
raistca
Posts: 15
Joined: Sat Mar 26, 2011 5:26 am

Post by raistca »

Oh haha lol. Yeah my pointer skills are rusty, but now that you "pointed" that out I feel like a moron (pun intended). Anyways though, is the filesystem created by irrlicht named "filesystem" or is it something else?

Thanks a bunch guys!
Radikalizm
Posts: 1215
Joined: Tue Jan 09, 2007 7:03 pm
Location: Leuven, Belgium

Post by Radikalizm »

You have to use the getFileSystem() getter function provided by the irrlicht device to access the file system

http://irrlicht.sourceforge.net/docu/cl ... 592de3e6ed
raistca
Posts: 15
Joined: Sat Mar 26, 2011 5:26 am

Post by raistca »

Ok cool that's working now. Maybe it's just because I've never worked with an engine before, but that was totally non-intuitive. I was hunting through every function of IFileSystem trying to get a clue and couldn't find jack, now the reason for that is obvious.

Thanks!
Post Reply