Page 1 of 1

How to use IFileSystem (data type issue)

Posted: Thu Apr 07, 2011 8:22 pm
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.

Posted: Thu Apr 07, 2011 8:31 pm
by ChaiRuiPeng
you should use the irrlicht define

Code: Select all

c8
wchar_t is a wide character, char is something else.[/code]

Posted: Thu Apr 07, 2011 9:54 pm
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! ;)

Posted: Thu Apr 07, 2011 10:19 pm
by raistca
ok so then how do I use read (or whatever else I need to use) to return a character or string?

Posted: Thu Apr 07, 2011 10:40 pm
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).

Posted: Fri Apr 08, 2011 2:10 am
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);

Posted: Fri Apr 08, 2011 2:25 am
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

Posted: Fri Apr 08, 2011 10:35 am
by polylux
Copy that.

Posted: Fri Apr 08, 2011 1:22 pm
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!

Posted: Fri Apr 08, 2011 1:24 pm
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

Posted: Fri Apr 08, 2011 8:54 pm
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!