Game Development Community

Writing files to a releative path

by Joshua Jewell · in Torque Game Builder · 12/07/2007 (1:31 pm) · 4 replies

Let me first start by apologizing if there is a thread that already covers this. I was unable to find it.

Anyway I have recently had the problem of trying to write files using a relative path. The FileObject.openForWrite() method only accepts an absolute path. This of course creates a problem if you want to store files and you are not sure exactly which file structure a user has. To solve this problem I added the following consoleFunction to the engine:

ConsoleFunction( makeFullPath, const char*, 2, 2, "filePath" )
{
	const char* filePath = argv[1];

	char* pBuffer = Con::getReturnBuffer(1024);
	Platform::makeFullPathName( filePath, pBuffer, 1024 );
	return pBuffer;
}

This method will take a relative path and turn it into an absolute one. Here is the example usage from script.

%fullPath = makeFullPath( %relativePath ) ;

Hopefully this helps anybody who may be in a similar situation.

#1
12/07/2007 (2:51 pm)
There is a problem with writing files at the moment. You're probably best off waiting a few weeks for 1.5.2 to come out.
#2
12/10/2007 (5:11 pm)
What is the problem? I have been able to write out simple files without any noticeable artifacts.
#3
12/19/2007 (12:43 pm)
I'm glad I found this. I just spent four hours trying to get some simple saving code to work. I just tried an absolute path and sure enough, it worked. I was hoping I wouldn't have to make any modifications to the engine though. Is there a way I could get the absolute path with a script function?
#4
12/19/2007 (12:55 pm)
It would appear that GB 1.6 has fixed the file problem.