May 23, 2012, 05:01:05 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: Please report any bugs or issues that you might be encountering with the Beta in the Support System so that we can better keep track of any oustanding issues that may come up.

GameCore Support System
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: Write in a file  (Read 1139 times)
Elca
Newbie
*
Posts: 2


View Profile
« on: January 04, 2011, 08:33:46 PM »

Hi all,

I have a problem to write in a file with the File class.

This is my code:

Code:
String path = "C:/Users/Elca/Documents/Games/test.txt";
FileInfo info;
print(GetFileInfo(path,info));
print(info.IsWritable());
File f( path, "Open");
f.WriteLine("Hello");

When I start the game with the editor, the 2 print function return True and the WriteLine return this error:

Quote
File::Write - Write operation not permitted on this file handle

An idea ?


And how to create a file ? I don't found any function to do that.




Logged
Elca
Newbie
*
Posts: 2


View Profile
« Reply #1 on: January 06, 2011, 06:02:50 AM »

Anyone have a sample code to write in a file which I can compare?

Logged
LutinMalefique
Full Member
***
Posts: 146



View Profile WWW
« Reply #2 on: January 06, 2011, 01:09:07 PM »

hi,
i haven't use this function since your post, and i haven't succeed yet. I will take a closer look this week-end.
Maybe it's something with the "open" function when you handle to a file, but "write" doesn't work Sad
Logged

http://lutinmalefique.wordpress.com/
"Just remember: a damn game can be played, and if you have not created something that can be played, it's not a damn game!" Derek Yu
LutinMalefique
Full Member
***
Posts: 146



View Profile WWW
« Reply #3 on: January 16, 2011, 04:50:44 AM »

hi Elca,

i hope you've succeed or find another solution because in my side i haven't succeed in using that fonction.
Logged

http://lutinmalefique.wordpress.com/
"Just remember: a damn game can be played, and if you have not created something that can be played, it's not a damn game!" Derek Yu
LutinMalefique
Full Member
***
Posts: 146



View Profile WWW
« Reply #4 on: February 11, 2011, 07:17:13 PM »

hi,
I do not know if your problem is still relevant but, recently, i've worked on file's writing. OptionsFile is the only function with which I managed to write something on a file, here's an example:

Code:
         OptionsFile testRecord("test");
        //
String testFile = "test.txt";
testRecord.New (testFile);
        //
testRecord.SetVariable("something", yourVariable);
//
testRecord.Save();
Logged

http://lutinmalefique.wordpress.com/
"Just remember: a damn game can be played, and if you have not created something that can be played, it's not a damn game!" Derek Yu
gekido
Guest
« Reply #5 on: March 21, 2011, 01:42:47 AM »

File management in gamecore is basically a wrapper for the basic C-style functions:

http://www.exforsys.com/tutorials/c-language/file-management-in-c.html

You can open files in one of 3 modes - as described in the above tutorial:

The second statement also specifies the purpose of opening the file. The mode does this job.

R open the file for read only.
W open the file for writing only.
A open the file for appending data to it.

In GameCore terms, these 3 properties are defined as:

Open
Create
Append

So in your script sample, you weren't able to write to the file essentially because you were opening them in 'read only' mode.

http://gamecore3d.com/docs/scripting-reference/classes/File

I just updated the documentation to hopefully clarify this information as well for future users.
Logged
LutinMalefique
Full Member
***
Posts: 146



View Profile WWW
« Reply #6 on: March 31, 2011, 11:33:56 AM »

Thank you for the clarification Gekido, but i have a problem with the creation of File.
Code:
String path = "C:/benchSponza.txt";
File CreateBench( path, "Create");
The "code creation" is done in a custom script (outside any scope, like global variables) - my Sponza controller for Day/Night, postFx activation...- and it works well when game is tested in editor. But not with an exported game, an error message say
Quote
archive C:/benchSponza.txt is not opened for writing for file C:/benchSponza.txt.
I've try to put code creation in the menu script, and my "sponza controller" open that file to append new data, no success.

Anyone have clues to create a file with export game  Huh
Logged

http://lutinmalefique.wordpress.com/
"Just remember: a damn game can be played, and if you have not created something that can be played, it's not a damn game!" Derek Yu
davidochoa
Newbie
*
Posts: 34


View Profile
« Reply #7 on: April 01, 2011, 06:40:37 PM »

You may need to use the DocumentsPath alias:

Code:
String path = "[documents]\\benchSponza.txt";

Inside the editor the file is created in the project root folder, for exported games it's in the folder defined in DocumentsPath.
Logged
LutinMalefique
Full Member
***
Posts: 146



View Profile WWW
« Reply #8 on: April 02, 2011, 03:35:53 AM »

ok thank you it works. The file is created in the MyGames folder.
Logged

http://lutinmalefique.wordpress.com/
"Just remember: a damn game can be played, and if you have not created something that can be played, it's not a damn game!" Derek Yu
gekido
Guest
« Reply #9 on: April 05, 2011, 01:23:04 PM »

That's a Window's security issue - in a typical 'user' account, applications can only write into a limited subset of folders by default within the user's home folder

Any data / files that you need / want to write from your game after export, you need to use one of the available 'aliases' that gamecore provides for you.

http://gamecore3d.com/docs/user-guide/scripting/introduction/aliases


Logged
Pages: [1]
  Print  
 
Jump to:  

 
Powered by MySQL Powered by PHP bluBlur Skin © 2006, hbSkins
Powered by SMF 1.1.14 | SMF © 2006-2011, Simple Machines LLC
Valid XHTML 1.0! Valid CSS!